Beispiel #1
0
        private void B_Load_Click(object sender, EventArgs e)
        {
            bool skipOccupiedSlots    = (ModifierKeys & Keys.Alt) != 0;
            bool importCheatClipboard = (ModifierKeys & Keys.Control) != 0;

            if (importCheatClipboard && Clipboard.ContainsText())
            {
                var text  = Clipboard.GetText();
                var bytes = ItemCheatCode.ReadCode(text);
                if (bytes.Length % ItemArray.ItemSize == 0)
                {
                    ImportItemData(bytes, skipOccupiedSlots);
                    return;
                }
            }

            using var sfd = new OpenFileDialog
                  {
                      Filter   = "New Horizons Inventory (*.nhi)|*.nhi|All files (*.*)|*.*",
                      FileName = "items.nhi",
                  };
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var data = File.ReadAllBytes(sfd.FileName);

            ImportItemData(data, skipOccupiedSlots);
        }
Beispiel #2
0
        private void B_Load_Click(object sender, EventArgs e)
        {
            if (ModifierKeys == Keys.Control && Clipboard.ContainsText())
            {
                var text = Clipboard.GetText();
                var bytes = ItemCheatCode.ReadCode(text);
                var expect = Items[0].ToBytesClass().Length;
                if (bytes.Length % expect == 0)
                {
                    ImportItemData(bytes, expect);
                    return;
                }
            }

            using var sfd = new OpenFileDialog
            {
                Filter = "New Horizons Inventory (*.nhi)|*.nhi|All files (*.*)|*.*",
                FileName = "items.nhi",
            };
            if (sfd.ShowDialog() != DialogResult.OK)
                return;

            var data = File.ReadAllBytes(sfd.FileName);
            ImportItemData(data, Items[0].ToBytesClass().Length);
        }
    public void LoadCheats()
    {
        if (UI_ACItemGrid.LastInstanceOfItemGrid == null)
        {
            return;
        }
        string parseable = CheatField.text;
        ItemArrayEditor <Item> ItemArray = new ItemArrayEditor <Item>(UI_ACItemGrid.LastInstanceOfItemGrid.Items);

        if (parseable != "")
        {
            var bytes = ItemCheatCode.ReadCode(parseable);
            if (bytes.Length % ItemArray.ItemSize == 0)
            {
                ItemArray.ImportItemDataX(bytes, EmptySpacesOnly.isOn, 0);
            }
        }

        for (int i = 0; i < ItemArray.Items.Count; ++i)
        {
            UI_ACItemGrid.LastInstanceOfItemGrid.SetItemAt(ItemArray.Items[i], i, i == (ItemArray.Items.Count - 1));
        }
    }
Beispiel #4
0
    public void LoadCheats()
    {
        string parseable = CheatField.text;
        ItemArrayEditor <Item> ItemArray;

        if (SaveMode.value == 0)
        {
            ItemArray = new ItemArrayEditor <Item>(UI_ACItemGrid.LastInstanceOfItemGrid.Items);
        }
        else
        {
            ItemArray = new ItemArrayEditor <Item>(GetNoItems(40));
        }

        byte[] allItemBytes = null;

        if (EnteredValueParseMode.value == 0) // 0 == cheat
        {
            if (parseable != "")
            {
                var bytes = ItemCheatCode.ReadCode(parseable);
                ItemArray = new ItemArrayEditor <Item>(UI_ACItemGrid.LastInstanceOfItemGrid.Items);
                if (bytes.Length % ItemArray.ItemSize == 0)
                {
                    ItemArray.ImportItemDataX(bytes, EmptySpacesOnly.isOn, 0);
                }
                allItemBytes = bytes;
            }
        }
        else // 1 == hexdata
        {
            if (parseable != "")
            {
                List <byte[]> loadedItems = new List <byte[]>();
                var           split       = parseable.Split(new[] { " ", "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < split.Length; ++i)
                {
                    var itemText = split[i];
                    var item     = itemText.Trim();
                    var asBytes  = GetBytesFromString(item);
                    loadedItems.Add(asBytes);
                }

                while (loadedItems.Count < 40)
                {
                    loadedItems.Add(Item.NO_ITEM.ToBytesClass());
                }

                allItemBytes = new byte[Item.SIZE * 40];
                for (int i = 0; i < loadedItems.Count; ++i)
                {
                    Array.Copy(loadedItems[i], 0, allItemBytes, i * Item.SIZE, Item.SIZE);
                }

                ItemArray.ImportItemDataX(allItemBytes, EmptySpacesOnly.isOn, 0);
            }
        }


        if (SaveMode.value == 0) // 0 == inventory
        {
            if (UI_ACItemGrid.LastInstanceOfItemGrid == null)
            {
                return;
            }

            for (int i = 0; i < ItemArray.Items.Count; ++i)
            {
                UI_ACItemGrid.LastInstanceOfItemGrid.SetItemAt(ItemArray.Items[i], i, i == (ItemArray.Items.Count - 1));
            }
        }
        else
        {
            if (allItemBytes != null)
            {
                UI_NFSOACNHHandler.LastInstanceOfNFSO.SaveFile("NHIItems.nhi", allItemBytes);
            }
            else
            {
                throw new Exception("No valid items.");
            }
        }
    }