예제 #1
0
        private void UpdateFileList()
        {
            fileListView.BeginUpdate();
            string search = searchBox.Text.ToLower();

            if (_lastSearch != null && search.Contains(_lastSearch))
            {
                for (int i = 0; i < fileListView.Items.Count; i++)
                {
                    if (!_fileItemsText[(int)fileListView.Items[i].Tag].Contains(search))
                    {
                        fileListView.Items.RemoveAt(i--);
                    }
                }
            }
            else
            {
                fileListView.Items.Clear();
                for (int i = 0; i < _game.GetFileCount(); i++)
                {
                    var file = _game.GetFileFromIndex(i);
                    if (!file.Valid())
                    {
                        continue;
                    }

                    if (_fileItemsText[i].Contains(search))
                    {
                        string name = _game.GetFileName(file.VRomStart);
                        string vrom = $"{file.VRomStart:X8}-{file.VRomEnd:X8}";
                        string rom  = $"{file.RomStart:X8}-{file.RomEnd:X8}";
                        string type = "Unknow";

                        var item = fileListView.Items.Add(name);
                        item.SubItems.AddRange(new string[] { vrom, rom, type });
                        item.Tag = i;
                    }
                }
            }
            _lastSearch = search;
            fileListView.EndUpdate();
        }
예제 #2
0
        public DmaFileSelectForm(Z64Game game)
        {
            InitializeComponent();
            _game = game;

            _fileItemsText = new string[_game.GetFileCount()];
            for (int i = 0; i < _game.GetFileCount(); i++)
            {
                var file = _game.GetFileFromIndex(i);
                if (!file.Valid())
                {
                    continue;
                }

                _fileItemsText[i] = ($"{_game.GetFileName(file.VRomStart).ToLower()} {file.VRomStart:x8} {file.VRomEnd:x8}");
            }
            UpdateFileList();
        }
예제 #3
0
 private byte[] ReadBytes(uint addr, int size)
 {
     if (comboBoxAddressType.SelectedIndex == 0) // VRAM
     {
         return(_game.Memory.ReadBytes(addr, size));
     }
     else // VROM
     {
         for (int i = 0; i < _game.GetFileCount(); i++)
         {
             var file = _game.GetFileFromIndex(i);
             if (addr >= file.VRomStart && addr < file.VRomEnd)
             {
                 byte[] buffer = new byte[size];
                 Buffer.BlockCopy(file.Data, (int)(addr - (uint)file.VRomStart), buffer, 0, size);
                 return(buffer);;
             }
         }
     }
     throw new Exception();
 }
예제 #4
0
        private void UpdateOutput(object sender, EventArgs e)
        {
            StringWriter sw = new StringWriter();

            if (uint.TryParse(textBoxInput.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint addr))
            {
                switch (comboBox1.SelectedIndex)
                {
                case 0:     // ROM
                {
                    for (int i = 0; i < _game.GetFileCount(); i++)
                    {
                        var file = _game.GetFileFromIndex(i);
                        if (addr >= file.RomStart && addr < file.RomEnd)
                        {
                            int diff = (int)(addr - file.RomStart);
                            if (file.Compressed)
                            {
                                sw.WriteLine("Cannot determine offset because the file is compressed");
                            }
                            string vromStr = file.Compressed
                                        ? $"{file.VRomStart:X8} + ?"
                                        : $"{file.VRomStart + diff:X8} ({file.VRomStart:X8} + 0x{diff:X})";
                            sw.WriteLine($"VROM: {vromStr}");

                            sw.WriteLine($"File: \"{_game.GetFileName(file.VRomStart)}\" + " + (file.Compressed ? "?" : $"0x{diff:X}"));
                            if (_game.Memory.VromToVram((uint)file.VRomStart, out uint vram))
                            {
                                string vramStr = file.Compressed
                                            ? $"{vram:X8} + ?"
                                            : $"{vram+diff:X8} ({vram:X8} + 0x{diff:X})";
                                sw.WriteLine($"VRAM: {vramStr}");
                            }
                            else
                            {
                                sw.WriteLine("VRAM: Not in VRAM");
                            }
                            break;
                        }
                    }
                    break;
                }

                case 1:     // VROM
                {
                    for (int i = 0; i < _game.GetFileCount(); i++)
                    {
                        var file = _game.GetFileFromIndex(i);
                        if (addr >= file.VRomStart && addr < file.VRomEnd)
                        {
                            int diff = (int)(addr - file.VRomStart);
                            sw.WriteLine($"ROM: {file.RomStart+diff:X8} ({file.RomStart:X8} + 0x{diff:X})");
                            sw.WriteLine($"File: \"{_game.GetFileName(file.VRomStart)}\" + 0x{diff:X}");
                            if (_game.Memory.VromToVram(addr, out uint vram))
                            {
                                sw.WriteLine($"VRAM: {vram:X8} ({(vram-diff):X8} + 0x{diff:X})");
                            }
                            else
                            {
                                sw.WriteLine("VRAM: Not in VRAM");
                            }
                            break;
                        }
                    }
                    break;
                }

                case 2:     // VRAM
                {
                    if (_game.Memory.VramToVrom(addr, out uint vrom))
                    {
                        for (int i = 0; i < _game.GetFileCount(); i++)
                        {
                            var file = _game.GetFileFromIndex(i);
                            if (vrom >= file.VRomStart && vrom < file.VRomEnd)
                            {
                                int diff = (int)(vrom - file.VRomStart);
                                sw.WriteLine($"VROM: {(file.VRomStart + diff):X8} ({file.VRomStart:X8} + 0x{diff:X})");
                                sw.WriteLine($"ROM: {(file.RomStart + diff):X8} ({file.RomStart:X8} + 0x{diff:X})");
                                sw.WriteLine($"File: \"{_game.GetFileName(file.VRomStart)}\" + 0x{diff:X}");
                                break;
                            }
                        }
                    }
                    else
                    {
                        sw.WriteLine("Cannot convert to ROM/VROM");
                    }
                    break;
                }
                }
            }
            else
            {
                sw.WriteLine("Invalid address");
            }


            textBoxOutput.Text = sw.ToString();
        }
예제 #5
0
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = "";
            openFileDialog1.Filter   = $"{Filters.N64}|{Filters.ALL}";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                _game = null;
                Application.OpenForms.OfType <Form>().ToList().ForEach(f =>
                {
                    if (f != this)
                    {
                        f.Close();
                    }
                });

                StartTask(() => {
                    try
                    {
                        _game = new Z64Game(openFileDialog1.FileName, ProcessCallback);
                        if (!Z64Version.ContainsConfig(_game.Version))
                        {
                            Invoke(new Action(() =>
                            {
                                MessageBox.Show($"No config file found for this version!\r\n(should be versions/{_game.Version}.json)", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }));
                        }
                    }
                    catch (Exception ex)
                    {
                        Invoke(new Action(() =>
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }));
                    }

                    Invoke(new Action(() =>
                    {
                        if (_game != null)
                        {
                            Text = $"Z64 Utils - {Path.GetFileName(openFileDialog1.FileName)} [ver. {_game.Version} ({_game.BuildID})]";

                            _fileItemsText = new string[_game.GetFileCount()];
                            for (int i = 0; i < _game.GetFileCount(); i++)
                            {
                                var file = _game.GetFileFromIndex(i);
                                if (!file.Valid())
                                {
                                    continue;
                                }

                                _fileItemsText[i] = ($"{_game.GetFileName(file.VRomStart).ToLower()} {file.VRomStart:x8} {file.VRomEnd:x8}");
                            }

                            _lastSearch = null;
                            UpdateFileList();
                        }
                        UpdateControls();
                        GC.Collect();
                    }));
                });
            }
        }