2011-03-16 03:56:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
2011-03-16 14:37:01 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Globalization;
|
2011-03-16 03:56:22 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
|
|
|
|
public partial class Cheats : Form
|
|
|
|
|
{
|
2011-03-16 15:48:47 +00:00
|
|
|
|
//Input validation on address & value boxes
|
|
|
|
|
//Set address box text load based on memory domain size
|
|
|
|
|
//Memory domains
|
|
|
|
|
//File format - saving & loading
|
|
|
|
|
//Shortcuts for Cheat menu items
|
2011-03-17 03:41:14 +00:00
|
|
|
|
//Edit button enabled conditionally on highlighted listview item
|
2011-03-17 14:55:40 +00:00
|
|
|
|
//ListView click event should update add cheat box
|
2011-03-16 15:48:47 +00:00
|
|
|
|
|
2011-03-16 03:56:22 +00:00
|
|
|
|
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
|
|
|
|
|
int defaultHeight;
|
|
|
|
|
|
|
|
|
|
List<Cheat> cheatList = new List<Cheat>();
|
|
|
|
|
string currentCheatFile = "";
|
|
|
|
|
bool changes = false;
|
2011-03-16 15:48:47 +00:00
|
|
|
|
|
2011-03-16 03:56:22 +00:00
|
|
|
|
public List<Cheat> GetCheatList()
|
|
|
|
|
{
|
|
|
|
|
List<Cheat> c = new List<Cheat>();
|
|
|
|
|
for (int x = 0; x < cheatList.Count; x++)
|
|
|
|
|
c.Add(new Cheat(cheatList[x]));
|
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
2011-03-16 15:48:47 +00:00
|
|
|
|
|
2011-03-16 03:56:22 +00:00
|
|
|
|
public Cheats()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2011-03-16 14:37:01 +00:00
|
|
|
|
Closing += (o, e) => SaveConfigSettings();
|
2011-03-17 02:21:14 +00:00
|
|
|
|
CheatListView.QueryItemText += new QueryItemTextHandler(CheatListView_QueryItemText);
|
|
|
|
|
CheatListView.QueryItemBkColor += new QueryItemBkColorHandler(CheatListView_QueryItemBkColor);
|
|
|
|
|
CheatListView.VirtualMode = true;
|
2011-03-16 14:37:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-16 15:48:47 +00:00
|
|
|
|
protected override void OnClosing(CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!AskSave())
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
base.OnClosing(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheatListView_QueryItemBkColor(int index, int column, ref Color color)
|
|
|
|
|
{
|
|
|
|
|
if (cheatList[index].address < 0)
|
|
|
|
|
color = this.BackColor;
|
2011-03-17 14:55:40 +00:00
|
|
|
|
else if (cheatList[index].enabled)
|
|
|
|
|
color = Color.Pink;
|
2011-03-16 15:48:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheatListView_QueryItemText(int index, int column, out string text)
|
|
|
|
|
{
|
|
|
|
|
text = "";
|
|
|
|
|
if (column == 0) //Name
|
|
|
|
|
{
|
|
|
|
|
text = cheatList[index].name;
|
|
|
|
|
}
|
|
|
|
|
if (column == 1) //Address
|
|
|
|
|
{
|
|
|
|
|
text = String.Format("{0:X" + GetNumDigits((Global.Emulator.MainMemory.Size - 1)).ToString() + "}", cheatList[index].address);
|
|
|
|
|
}
|
|
|
|
|
if (column == 2) //Value
|
|
|
|
|
{
|
2011-03-17 14:55:40 +00:00
|
|
|
|
text = String.Format("{0:X2}", cheatList[index].value);
|
2011-03-16 15:48:47 +00:00
|
|
|
|
}
|
2011-03-17 03:59:03 +00:00
|
|
|
|
if (column == 3) //Enabled
|
2011-03-16 15:48:47 +00:00
|
|
|
|
{
|
2011-03-17 14:55:40 +00:00
|
|
|
|
if (cheatList[index].enabled)
|
|
|
|
|
text = "*";
|
|
|
|
|
else
|
|
|
|
|
text = "";
|
2011-03-16 15:48:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int GetNumDigits(Int32 i)
|
|
|
|
|
{
|
|
|
|
|
if (i < 0x10000) return 4;
|
|
|
|
|
if (i < 0x1000000) return 6;
|
|
|
|
|
else return 8;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-16 14:37:01 +00:00
|
|
|
|
private void Cheats_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadConfigSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-16 15:48:47 +00:00
|
|
|
|
public void AddCheat(Cheat c)
|
|
|
|
|
{
|
|
|
|
|
cheatList.Add(c);
|
|
|
|
|
DisplayCheatsList();
|
2011-03-17 02:21:14 +00:00
|
|
|
|
CheatListView.Refresh();
|
2011-03-16 15:48:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-17 02:21:14 +00:00
|
|
|
|
public void LoadCheatFromRecent(string file)
|
2011-03-16 14:37:01 +00:00
|
|
|
|
{
|
|
|
|
|
bool z = true;
|
2011-03-16 15:48:47 +00:00
|
|
|
|
|
2011-03-16 14:37:01 +00:00
|
|
|
|
if (changes) z = AskSave();
|
|
|
|
|
|
|
|
|
|
if (z)
|
|
|
|
|
{
|
2011-03-16 15:48:47 +00:00
|
|
|
|
bool r = LoadCheatFile(file, false);
|
2011-03-16 14:37:01 +00:00
|
|
|
|
if (!r)
|
|
|
|
|
{
|
|
|
|
|
DialogResult result = MessageBox.Show("Could not open " + file + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
|
|
|
|
|
if (result == DialogResult.Yes)
|
2011-03-16 15:48:47 +00:00
|
|
|
|
Global.Config.RecentCheats.Remove(file);
|
2011-03-16 14:37:01 +00:00
|
|
|
|
}
|
2011-03-16 15:48:47 +00:00
|
|
|
|
DisplayCheatsList();
|
2011-03-16 14:37:01 +00:00
|
|
|
|
changes = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-17 02:21:14 +00:00
|
|
|
|
private void UpdateAutoLoadCheats()
|
|
|
|
|
{
|
|
|
|
|
autoLoadToolStripMenuItem.Checked = Global.Config.AutoLoadCheats ^= true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//Clear out recent Roms list
|
|
|
|
|
//repopulate it with an up to date list
|
|
|
|
|
recentToolStripMenuItem.DropDownItems.Clear();
|
|
|
|
|
|
|
|
|
|
if (Global.Config.RecentCheats.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
recentToolStripMenuItem.DropDownItems.Add("None");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int x = 0; x < Global.Config.RecentCheats.Length(); x++)
|
|
|
|
|
{
|
|
|
|
|
string path = Global.Config.RecentCheats.GetRecentFileByPosition(x);
|
|
|
|
|
var item = new ToolStripMenuItem();
|
|
|
|
|
item.Text = path;
|
|
|
|
|
item.Click += (o, ev) => LoadCheatFromRecent(path);
|
|
|
|
|
recentToolStripMenuItem.DropDownItems.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
recentToolStripMenuItem.DropDownItems.Add("-");
|
|
|
|
|
|
|
|
|
|
var clearitem = new ToolStripMenuItem();
|
|
|
|
|
clearitem.Text = "&Clear";
|
|
|
|
|
clearitem.Click += (o, ev) => Global.Config.RecentCheats.Clear();
|
|
|
|
|
recentToolStripMenuItem.DropDownItems.Add(clearitem);
|
|
|
|
|
|
|
|
|
|
var auto = new ToolStripMenuItem();
|
|
|
|
|
auto.Text = "&Auto-Load";
|
|
|
|
|
auto.Click += (o, ev) => UpdateAutoLoadCheats();
|
|
|
|
|
if (Global.Config.AutoLoadCheats == true)
|
|
|
|
|
auto.Checked = true;
|
|
|
|
|
else
|
|
|
|
|
auto.Checked = false;
|
|
|
|
|
recentToolStripMenuItem.DropDownItems.Add(auto);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-16 14:37:01 +00:00
|
|
|
|
private void LoadConfigSettings()
|
|
|
|
|
{
|
|
|
|
|
defaultWidth = Size.Width; //Save these first so that the user can restore to its original size
|
|
|
|
|
defaultHeight = Size.Height;
|
|
|
|
|
|
|
|
|
|
if (Global.Config.CheatsWndx >= 0 && Global.Config.CheatsWndy >= 0)
|
|
|
|
|
Location = new Point(Global.Config.CheatsWndx, Global.Config.CheatsWndy);
|
|
|
|
|
|
|
|
|
|
if (Global.Config.CheatsWidth >= 0 && Global.Config.CheatsHeight >= 0)
|
|
|
|
|
{
|
|
|
|
|
Size = new System.Drawing.Size(Global.Config.CheatsWidth, Global.Config.CheatsHeight);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveConfigSettings()
|
|
|
|
|
{
|
|
|
|
|
Global.Config.CheatsWndx = this.Location.X;
|
|
|
|
|
Global.Config.CheatsWndy = this.Location.Y;
|
|
|
|
|
Global.Config.CheatsWidth = this.Right - this.Left;
|
|
|
|
|
Global.Config.CheatsHeight = this.Bottom - this.Top;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisplayCheatsList()
|
|
|
|
|
{
|
2011-03-17 03:41:14 +00:00
|
|
|
|
UpdateNumberOfCheats();
|
2011-03-16 15:48:47 +00:00
|
|
|
|
CheatListView.ItemCount = cheatList.Count;
|
2011-03-16 14:37:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MoveUp()
|
|
|
|
|
{
|
2011-03-16 15:48:47 +00:00
|
|
|
|
ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices;
|
|
|
|
|
Cheat temp = new Cheat();
|
|
|
|
|
if (indexes[0] == 0) return;
|
|
|
|
|
foreach (int index in indexes)
|
|
|
|
|
{
|
|
|
|
|
temp = cheatList[index];
|
|
|
|
|
cheatList.Remove(cheatList[index]);
|
|
|
|
|
cheatList.Insert(index - 1, temp);
|
|
|
|
|
|
|
|
|
|
//Note: here it will get flagged many times redundantly potentially,
|
|
|
|
|
//but this avoids it being flagged falsely when the user did not select an index
|
|
|
|
|
Changes();
|
|
|
|
|
}
|
|
|
|
|
List<int> i = new List<int>();
|
|
|
|
|
for (int z = 0; z < indexes.Count; z++)
|
|
|
|
|
i.Add(indexes[z] - 1);
|
|
|
|
|
|
|
|
|
|
CheatListView.SelectedIndices.Clear();
|
|
|
|
|
for (int z = 0; z < i.Count; z++)
|
|
|
|
|
CheatListView.SelectItem(i[z], true);
|
|
|
|
|
|
2011-03-16 14:37:01 +00:00
|
|
|
|
|
2011-03-16 15:48:47 +00:00
|
|
|
|
DisplayCheatsList();
|
2011-03-16 14:37:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MoveDown()
|
|
|
|
|
{
|
|
|
|
|
ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices;
|
|
|
|
|
Cheat temp = new Cheat();
|
|
|
|
|
|
|
|
|
|
foreach (int index in indexes)
|
|
|
|
|
{
|
|
|
|
|
temp = cheatList[index];
|
|
|
|
|
|
|
|
|
|
if (index < cheatList.Count - 1)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
cheatList.Remove(cheatList[index]);
|
|
|
|
|
cheatList.Insert(index + 1, temp);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Note: here it will get flagged many times redundantly potnetially,
|
|
|
|
|
//but this avoids it being flagged falsely when the user did not select an index
|
|
|
|
|
Changes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<int> i = new List<int>();
|
|
|
|
|
for (int z = 0; z < indexes.Count; z++)
|
|
|
|
|
i.Add(indexes[z] + 1);
|
|
|
|
|
|
|
|
|
|
CheatListView.SelectedIndices.Clear();
|
|
|
|
|
//for (int z = 0; z < i.Count; z++)
|
|
|
|
|
//CheatListView.SelectItem(i[z], true); //TODO
|
|
|
|
|
|
|
|
|
|
DisplayCheatsList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toolStripButtonMoveUp_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MoveUp();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void moveUpToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MoveUp();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toolStripButtonMoveDown_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MoveDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void moveDownToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MoveDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Changes()
|
|
|
|
|
{
|
|
|
|
|
changes = true;
|
|
|
|
|
MessageLabel.Text = Path.GetFileName(currentCheatFile) + " *";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private FileInfo GetSaveFileFromUser()
|
|
|
|
|
{
|
|
|
|
|
var sfd = new SaveFileDialog();
|
|
|
|
|
sfd.InitialDirectory = Global.Config.LastRomPath;
|
|
|
|
|
sfd.Filter = "Cheat Files (*.cht)|*.cht|All Files|*.*";
|
|
|
|
|
sfd.RestoreDirectory = true;
|
|
|
|
|
Global.Sound.StopSound();
|
|
|
|
|
var result = sfd.ShowDialog();
|
|
|
|
|
Global.Sound.StartSound();
|
|
|
|
|
if (result != DialogResult.OK)
|
|
|
|
|
return null;
|
|
|
|
|
var file = new FileInfo(sfd.FileName);
|
|
|
|
|
Global.Config.LastRomPath = file.DirectoryName;
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SaveAs()
|
|
|
|
|
{
|
|
|
|
|
var file = GetSaveFileFromUser();
|
|
|
|
|
if (file != null)
|
|
|
|
|
{
|
|
|
|
|
SaveCheatFile(file.FullName);
|
|
|
|
|
currentCheatFile = file.FullName;
|
|
|
|
|
MessageLabel.Text = Path.GetFileName(currentCheatFile) + " saved.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SaveCheatFile(string path)
|
|
|
|
|
{
|
|
|
|
|
var file = new FileInfo(path);
|
|
|
|
|
|
|
|
|
|
using (StreamWriter sw = new StreamWriter(path))
|
|
|
|
|
{
|
|
|
|
|
string str = "";
|
|
|
|
|
|
|
|
|
|
for (int x = 0; x < cheatList.Count; x++)
|
|
|
|
|
{
|
|
|
|
|
//str += string.Format("{0:X4}", watchList[x].address) + "\t";
|
|
|
|
|
//str += watchList[x].GetTypeByChar().ToString() + "\t";
|
|
|
|
|
//str += watchList[x].GetSignedByChar().ToString() + "\t";
|
|
|
|
|
|
|
|
|
|
//if (watchList[x].bigendian == true)
|
|
|
|
|
// str += "1\t";
|
|
|
|
|
//else
|
|
|
|
|
// str += "0\t";
|
|
|
|
|
|
|
|
|
|
//str += watchList[x].notes + "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sw.WriteLine(str);
|
|
|
|
|
}
|
|
|
|
|
changes = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool AskSave()
|
|
|
|
|
{
|
|
|
|
|
if (changes)
|
|
|
|
|
{
|
|
|
|
|
DialogResult result = MessageBox.Show("Save Changes?", "Ram Watch", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
|
|
|
|
|
|
|
|
|
|
if (result == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
//TOOD: Do quicksave if filename, else save as
|
|
|
|
|
if (string.Compare(currentCheatFile, "") == 0)
|
|
|
|
|
{
|
|
|
|
|
SaveAs();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
SaveCheatFile(currentCheatFile);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (result == DialogResult.No)
|
|
|
|
|
return true;
|
|
|
|
|
else if (result == DialogResult.Cancel)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NewCheatList()
|
|
|
|
|
{
|
|
|
|
|
bool result = true;
|
|
|
|
|
if (changes) result = AskSave();
|
|
|
|
|
|
|
|
|
|
if (result == true)
|
|
|
|
|
{
|
|
|
|
|
cheatList.Clear();
|
|
|
|
|
DisplayCheatsList();
|
|
|
|
|
currentCheatFile = "";
|
|
|
|
|
changes = false;
|
|
|
|
|
MessageLabel.Text = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void newToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
NewCheatList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void newToolStripButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
NewCheatList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveToolStripButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (changes)
|
|
|
|
|
{
|
|
|
|
|
SaveCheatFile(currentCheatFile);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SaveAs();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.Compare(currentCheatFile, "") == 0) return;
|
|
|
|
|
|
|
|
|
|
if (changes)
|
|
|
|
|
SaveCheatFile(currentCheatFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SaveAs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private FileInfo GetFileFromUser()
|
|
|
|
|
{
|
|
|
|
|
var ofd = new OpenFileDialog();
|
|
|
|
|
ofd.InitialDirectory = Global.Config.LastRomPath;
|
|
|
|
|
ofd.Filter = "Cheat Files (*.cht)|*.cht|All Files|*.*";
|
|
|
|
|
ofd.RestoreDirectory = true;
|
|
|
|
|
|
|
|
|
|
Global.Sound.StopSound();
|
|
|
|
|
var result = ofd.ShowDialog();
|
|
|
|
|
Global.Sound.StartSound();
|
|
|
|
|
if (result != DialogResult.OK)
|
|
|
|
|
return null;
|
|
|
|
|
var file = new FileInfo(ofd.FileName);
|
|
|
|
|
Global.Config.LastRomPath = file.DirectoryName;
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LoadCheatFile(string path, bool append)
|
|
|
|
|
{
|
|
|
|
|
int y, z;
|
|
|
|
|
var file = new FileInfo(path);
|
|
|
|
|
if (file.Exists == false) return false;
|
|
|
|
|
|
|
|
|
|
using (StreamReader sr = file.OpenText())
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true; //TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenCheatFile()
|
|
|
|
|
{
|
|
|
|
|
var file = GetFileFromUser();
|
|
|
|
|
if (file != null)
|
|
|
|
|
{
|
|
|
|
|
bool r = true;
|
|
|
|
|
if (changes) r = AskSave();
|
|
|
|
|
if (r)
|
|
|
|
|
{
|
|
|
|
|
LoadCheatFile(file.FullName, false);
|
|
|
|
|
DisplayCheatsList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void openToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OpenCheatFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void openToolStripButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OpenCheatFile();
|
2011-03-16 03:56:22 +00:00
|
|
|
|
}
|
2011-03-16 15:48:47 +00:00
|
|
|
|
|
|
|
|
|
private void InsertSeparator()
|
|
|
|
|
{
|
|
|
|
|
Cheat c = new Cheat();
|
|
|
|
|
c.address = -1;
|
|
|
|
|
c.name = "Separator"; //TODO: remove me
|
|
|
|
|
|
|
|
|
|
ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices;
|
|
|
|
|
int x;
|
|
|
|
|
if (indexes.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
x = indexes[0];
|
|
|
|
|
if (indexes[0] > 0)
|
|
|
|
|
cheatList.Insert(indexes[0], c);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cheatList.Add(c);
|
|
|
|
|
DisplayCheatsList();
|
|
|
|
|
CheatListView.Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toolStripButtonSeparator_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InsertSeparator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void insertSeparatorToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InsertSeparator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Cheat MakeCheat()
|
|
|
|
|
{
|
|
|
|
|
Cheat c = new Cheat();
|
|
|
|
|
c.name = NameBox.Text;
|
|
|
|
|
c.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber); //TODO: validation
|
2011-03-17 14:55:40 +00:00
|
|
|
|
c.value = (byte)(int.Parse(ValueBox.Text, NumberStyles.HexNumber));
|
2011-03-16 15:48:47 +00:00
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddCheatButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AddCheat(MakeCheat());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addCheatToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AddCheat(MakeCheat());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveCheat()
|
|
|
|
|
{
|
|
|
|
|
Changes();
|
|
|
|
|
ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices;
|
|
|
|
|
if (indexes.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (int index in indexes)
|
|
|
|
|
{
|
|
|
|
|
cheatList.Remove(cheatList[indexes[0]]); //index[0] used since each iteration will make this the correct list index
|
|
|
|
|
}
|
|
|
|
|
DisplayCheatsList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cutToolStripButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RemoveCheat();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void removeCheatToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RemoveCheat();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateNumberOfCheats()
|
|
|
|
|
{
|
|
|
|
|
int z = cheatList.Count;
|
|
|
|
|
if (z == 1)
|
|
|
|
|
NumCheatsLabel.Text = z.ToString() + " cheat";
|
|
|
|
|
else
|
|
|
|
|
NumCheatsLabel.Text = z.ToString() + " cheats";
|
|
|
|
|
}
|
2011-03-17 02:21:14 +00:00
|
|
|
|
|
|
|
|
|
private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Global.Config.CheatsSaveWindowPosition ^= true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void optionsToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
saveWindowPositionToolStripMenuItem.Checked = Global.Config.CheatsSaveWindowPosition;
|
|
|
|
|
}
|
2011-03-17 03:41:14 +00:00
|
|
|
|
|
|
|
|
|
private void DuplicateCheat()
|
|
|
|
|
{
|
|
|
|
|
ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices;
|
|
|
|
|
if (indexes.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
Cheat c = new Cheat();
|
|
|
|
|
int x = indexes[0];
|
|
|
|
|
c.name = cheatList[x].name;
|
|
|
|
|
c.address = cheatList[x].address;
|
|
|
|
|
c.value = cheatList[x].value;
|
|
|
|
|
Changes();
|
|
|
|
|
cheatList.Add(c);
|
|
|
|
|
DisplayCheatsList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void copyToolStripButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DuplicateCheat();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void duplicateToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DuplicateCheat();
|
|
|
|
|
}
|
2011-03-17 14:55:40 +00:00
|
|
|
|
|
|
|
|
|
private void CheatListView_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices;
|
|
|
|
|
if (indexes.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
cheatList[indexes[0]].enabled ^= true;
|
|
|
|
|
CheatListView.Refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-16 03:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|