2013-09-07 05:17:29 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2013-10-20 16:19:59 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
2013-10-20 00:00:59 +00:00
|
|
|
|
|
2013-09-07 05:17:29 +00:00
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
|
|
|
|
class ToolHelpers
|
|
|
|
|
{
|
2013-10-17 00:21:45 +00:00
|
|
|
|
public static ToolStripMenuItem GenerateAutoLoadItem(RecentFiles recent)
|
|
|
|
|
{
|
|
|
|
|
var auto = new ToolStripMenuItem { Text = "&Auto-Load", Checked = recent.AutoLoad };
|
|
|
|
|
auto.Click += (o, ev) => recent.ToggleAutoLoad();
|
|
|
|
|
return auto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ToolStripItem[] GenerateRecentMenu(RecentFiles recent, Action<string> loadFileCallback)
|
|
|
|
|
{
|
|
|
|
|
var items = new List<ToolStripItem>();
|
|
|
|
|
|
|
|
|
|
if (recent.Empty)
|
|
|
|
|
{
|
|
|
|
|
var none = new ToolStripMenuItem { Enabled = false, Text = "None" };
|
|
|
|
|
items.Add(none);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (string filename in recent)
|
|
|
|
|
{
|
|
|
|
|
string temp = filename;
|
|
|
|
|
var item = new ToolStripMenuItem { Text = temp };
|
|
|
|
|
item.Click += (o, ev) => loadFileCallback(temp);
|
|
|
|
|
items.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
items.Add(new ToolStripSeparator());
|
|
|
|
|
|
|
|
|
|
var clearitem = new ToolStripMenuItem { Text = "&Clear" };
|
|
|
|
|
clearitem.Click += (o, ev) => recent.Clear();
|
|
|
|
|
items.Add(clearitem);
|
|
|
|
|
|
|
|
|
|
return items.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void HandleLoadError(RecentFiles recent, string path)
|
|
|
|
|
{
|
2013-10-20 00:00:59 +00:00
|
|
|
|
GlobalWinF.Sound.StopSound();
|
2013-10-17 00:21:45 +00:00
|
|
|
|
DialogResult result = MessageBox.Show("Could not open " + path + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
|
|
|
|
|
if (result == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
recent.Remove(path);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-20 00:00:59 +00:00
|
|
|
|
GlobalWinF.Sound.StartSound();
|
2013-10-17 00:21:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-29 15:42:00 +00:00
|
|
|
|
public static ToolStripMenuItem[] GenerateMemoryDomainMenuItems(Action<int> SetCallback, string SelectedDomain = "", int? maxSize = null)
|
2013-09-07 05:17:29 +00:00
|
|
|
|
{
|
|
|
|
|
var items = new List<ToolStripMenuItem>();
|
|
|
|
|
|
2013-10-20 00:00:59 +00:00
|
|
|
|
if (GlobalWinF.Emulator.MemoryDomains.Any())
|
2013-09-07 05:17:29 +00:00
|
|
|
|
{
|
|
|
|
|
int counter = 0;
|
2013-10-20 00:00:59 +00:00
|
|
|
|
foreach (var domain in GlobalWinF.Emulator.MemoryDomains)
|
2013-09-07 05:17:29 +00:00
|
|
|
|
{
|
|
|
|
|
string temp = domain.ToString();
|
|
|
|
|
var item = new ToolStripMenuItem { Text = temp };
|
|
|
|
|
|
|
|
|
|
int index = counter;
|
|
|
|
|
item.Click += (o, ev) => SetCallback(index);
|
|
|
|
|
|
|
|
|
|
if (temp == SelectedDomain)
|
|
|
|
|
{
|
|
|
|
|
item.Checked = true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-29 15:42:00 +00:00
|
|
|
|
if (maxSize.HasValue && domain.Size > maxSize.Value)
|
|
|
|
|
{
|
|
|
|
|
item.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-07 05:17:29 +00:00
|
|
|
|
items.Add(item);
|
|
|
|
|
counter++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return items.ToArray();
|
|
|
|
|
}
|
2013-09-08 04:13:31 +00:00
|
|
|
|
|
2013-10-05 15:45:39 +00:00
|
|
|
|
public static void PopulateMemoryDomainDropdown(ref ComboBox dropdown, MemoryDomain startDomain)
|
|
|
|
|
{
|
|
|
|
|
dropdown.Items.Clear();
|
2013-10-20 00:00:59 +00:00
|
|
|
|
if (GlobalWinF.Emulator.MemoryDomains.Count > 0)
|
2013-10-05 15:45:39 +00:00
|
|
|
|
{
|
2013-10-20 00:00:59 +00:00
|
|
|
|
foreach (var domain in GlobalWinF.Emulator.MemoryDomains)
|
2013-10-05 15:45:39 +00:00
|
|
|
|
{
|
|
|
|
|
var result = dropdown.Items.Add(domain.ToString());
|
|
|
|
|
if (domain.Name == startDomain.Name)
|
|
|
|
|
{
|
|
|
|
|
dropdown.SelectedIndex = result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-14 01:37:09 +00:00
|
|
|
|
public static void UpdateCheatRelatedTools()
|
2013-09-23 16:01:19 +00:00
|
|
|
|
{
|
2013-10-20 00:00:59 +00:00
|
|
|
|
GlobalWinF.MainForm.RamWatch1.UpdateValues();
|
|
|
|
|
GlobalWinF.MainForm.HexEditor1.UpdateValues();
|
|
|
|
|
GlobalWinF.MainForm.Cheats_UpdateValues();
|
|
|
|
|
GlobalWinF.MainForm.RamSearch1.UpdateValues();
|
|
|
|
|
GlobalWinF.MainForm.UpdateCheatStatus();
|
2013-10-14 01:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void UnfreezeAll()
|
|
|
|
|
{
|
2013-10-20 00:00:59 +00:00
|
|
|
|
GlobalWinF.CheatList.DisableAll();
|
2013-10-14 01:37:09 +00:00
|
|
|
|
UpdateCheatRelatedTools();
|
2013-09-23 16:01:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-08 04:13:31 +00:00
|
|
|
|
public static void FreezeAddress(List<Watch> watches)
|
|
|
|
|
{
|
|
|
|
|
foreach(var watch in watches)
|
|
|
|
|
{
|
2013-10-06 18:44:51 +00:00
|
|
|
|
if (!watch.IsSeparator)
|
|
|
|
|
{
|
2013-10-20 00:00:59 +00:00
|
|
|
|
GlobalWinF.CheatList.Add(
|
2013-10-13 16:05:28 +00:00
|
|
|
|
new Cheat(watch, watch.Value.Value, compare: null, enabled: true)
|
|
|
|
|
);
|
2013-10-06 18:44:51 +00:00
|
|
|
|
}
|
2013-09-08 04:13:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-14 01:37:09 +00:00
|
|
|
|
UpdateCheatRelatedTools();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void UnfreezeAddress(List<Watch> watches)
|
|
|
|
|
{
|
|
|
|
|
foreach (var watch in watches)
|
|
|
|
|
{
|
|
|
|
|
if (!watch.IsSeparator)
|
|
|
|
|
{
|
2013-10-20 00:00:59 +00:00
|
|
|
|
GlobalWinF.CheatList.Remove(watch);
|
2013-10-14 01:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateCheatRelatedTools();
|
2013-09-08 04:13:31 +00:00
|
|
|
|
}
|
2013-09-29 16:09:48 +00:00
|
|
|
|
|
|
|
|
|
public static void ViewInHexEditor(MemoryDomain domain, IEnumerable<int> addresses)
|
|
|
|
|
{
|
2013-10-20 00:00:59 +00:00
|
|
|
|
GlobalWinF.MainForm.LoadHexEditor();
|
|
|
|
|
GlobalWinF.MainForm.HexEditor1.SetDomain(domain);
|
|
|
|
|
GlobalWinF.MainForm.HexEditor1.SetToAddresses(addresses.ToList());
|
2013-09-29 16:09:48 +00:00
|
|
|
|
}
|
2013-10-03 23:58:56 +00:00
|
|
|
|
|
|
|
|
|
public static MemoryDomain DomainByName(string name)
|
|
|
|
|
{
|
|
|
|
|
//Attempts to find the memory domain by name, if it fails, it defaults to index 0
|
2013-10-20 00:00:59 +00:00
|
|
|
|
foreach (MemoryDomain domain in GlobalWinF.Emulator.MemoryDomains)
|
2013-10-03 23:58:56 +00:00
|
|
|
|
{
|
|
|
|
|
if (domain.Name == name)
|
|
|
|
|
{
|
|
|
|
|
return domain;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-20 00:00:59 +00:00
|
|
|
|
return GlobalWinF.Emulator.MainMemory;
|
2013-10-03 23:58:56 +00:00
|
|
|
|
}
|
2013-10-04 16:06:08 +00:00
|
|
|
|
|
|
|
|
|
public static void AddColumn(ListView listView, string columnName, bool enabled, int columnWidth)
|
|
|
|
|
{
|
|
|
|
|
if (enabled)
|
|
|
|
|
{
|
|
|
|
|
if (listView.Columns[columnName] == null)
|
|
|
|
|
{
|
|
|
|
|
ColumnHeader column = new ColumnHeader
|
|
|
|
|
{
|
|
|
|
|
Name = columnName,
|
|
|
|
|
Text = columnName.Replace("Column", ""),
|
|
|
|
|
Width = columnWidth,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
listView.Columns.Add(column);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-07 05:17:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|