Refactor a bunch of cheats code, and fix a bug where exceptions can be thrown by the cheats dialog when working in other tool dialogs.

This commit is contained in:
adelikat 2013-08-25 04:23:27 +00:00
parent 61236bf763
commit 4bd6103574
12 changed files with 264 additions and 225 deletions

View File

@ -350,46 +350,46 @@ namespace BizHawk.MultiClient
{
Cheat c = new Cheat();
if (cheatname.Text.Length > 0)
c.name = cheatname.Text;
c.Name = cheatname.Text;
else
{
Processing = true;
GGCodeMaskBox.TextMaskFormat = MaskFormat.IncludeLiterals;
c.name = GGCodeMaskBox.Text;
c.Name = GGCodeMaskBox.Text;
GGCodeMaskBox.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
Processing = false;
}
if (String.IsNullOrWhiteSpace(AddressBox.Text))
c.address = 0;
c.Address = 0;
else
c.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
c.Address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
if (String.IsNullOrWhiteSpace(ValueBox.Text))
c.value = 0;
c.Value = 0;
else
c.value = (byte)(int.Parse(ValueBox.Text, NumberStyles.HexNumber));
c.Value = (byte)(int.Parse(ValueBox.Text, NumberStyles.HexNumber));
if (!String.IsNullOrWhiteSpace(CompareBox.Text))
{
try
{
c.compare = byte.Parse(CompareBox.Text, NumberStyles.HexNumber);
c.Compare = byte.Parse(CompareBox.Text, NumberStyles.HexNumber);
}
catch
{
c.compare = null;
c.Compare = null;
}
}
else
{
c.compare = null;
c.Compare = null;
}
for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
if (Global.Emulator.MemoryDomains[x].ToString() == "System Bus")
{
c.domain = Global.Emulator.MemoryDomains[x];
c.Domain = Global.Emulator.MemoryDomains[x];
c.Enable();
Global.MainForm.Cheats1.AddCheat(c);
break;

View File

@ -226,49 +226,49 @@ namespace BizHawk.MultiClient
Cheat d = new Cheat();
if (cheatname.Text.Length > 0)
{
c.name = cheatname.Text + " Part 1";
d.name = cheatname.Text + " Part 2";
c.Name = cheatname.Text + " Part 1";
d.Name = cheatname.Text + " Part 2";
}
else
{
Processing = true;
GGCodeMaskBox.TextMaskFormat = MaskFormat.IncludeLiterals;
c.name = GGCodeMaskBox.Text + " Part 1";
d.name = GGCodeMaskBox.Text + " Part 2";
c.Name = GGCodeMaskBox.Text + " Part 1";
d.Name = GGCodeMaskBox.Text + " Part 2";
GGCodeMaskBox.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
Processing = false;
}
if (String.IsNullOrWhiteSpace(AddressBox.Text))
{
c.address = 0;
d.address = 0 + 1;
c.Address = 0;
d.Address = 0 + 1;
}
else
{
c.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
d.address = c.address + 1;
c.Address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
d.Address = c.Address + 1;
}
if (String.IsNullOrWhiteSpace(ValueBox.Text))
{
c.value = 0;
d.value = 0;
c.Value = 0;
d.Value = 0;
}
else
{
c.value = (byte)((int.Parse(ValueBox.Text, NumberStyles.HexNumber) & 0xFF00) >> 8);
d.value = (byte)(int.Parse(ValueBox.Text, NumberStyles.HexNumber) & 0x00FF);
c.Value = (byte)((int.Parse(ValueBox.Text, NumberStyles.HexNumber) & 0xFF00) >> 8);
d.Value = (byte)(int.Parse(ValueBox.Text, NumberStyles.HexNumber) & 0x00FF);
}
c.compare = null;
d.compare = null;
c.Compare = null;
d.Compare = null;
for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
if (Global.Emulator.MemoryDomains[x].ToString() == "Rom Data")
{
c.domain = Global.Emulator.MemoryDomains[x];
c.Domain = Global.Emulator.MemoryDomains[x];
c.Enable();
Global.MainForm.Cheats1.AddCheat(c);
d.domain = Global.Emulator.MemoryDomains[x];
d.Domain = Global.Emulator.MemoryDomains[x];
d.Enable();
Global.MainForm.Cheats1.AddCheat(d);
break;

View File

@ -3017,14 +3017,14 @@ namespace BizHawk.MultiClient
{
Cheat c = new Cheat
{
name = code,
domain = Global.Emulator.MemoryDomains[1],
address = gg.Address,
value = (byte) gg.Value
Name = code,
Domain = Global.Emulator.MemoryDomains[1],
Address = gg.Address,
Value = (byte) gg.Value
};
if (gg.Compare != -1)
{
c.compare = (byte)gg.Compare;
c.Compare = (byte)gg.Compare;
}
c.Enable();
Global.MainForm.Cheats1.AddCheat(c);
@ -3042,16 +3042,16 @@ namespace BizHawk.MultiClient
{
Cheat c = new Cheat
{
name = code,
domain = Global.Emulator.MemoryDomains[1],
address = gg.Address,
value = (byte) gg.Value
Name = code,
Domain = Global.Emulator.MemoryDomains[1],
Address = gg.Address,
Value = (byte) gg.Value
};
if (gg.Compare != -1)
{
c.compare = (byte)gg.Compare;
c.Compare = (byte)gg.Compare;
}
Global.CheatList.RemoveCheat(Global.Emulator.MemoryDomains[1], c.address);
Global.CheatList.Remove(Global.Emulator.MemoryDomains[1], c.Address);
}
}
}

View File

@ -129,6 +129,10 @@ namespace BizHawk.MultiClient
public GBGameGenie GBgg { get { if (_gbgg == null) _gbgg = new GBGameGenie(); return _gbgg; } set { _gbgg = value; } }
public GenGameGenie Gengg { get { if (_gengg == null) _gengg = new GenGameGenie(); return _gengg; } set { _gengg = value; } }
public NESSoundConfig NesSound { get { if (_nessound == null) _nessound = new NESSoundConfig(); return _nessound; } set { _nessound = value; } }
//TODO: eventually start doing this, rather than tools attempting to talk to tools
public void Cheats_UpdateValues() { if (_cheats != null) { _cheats.UpdateValues(); } }
#if WINDOWS
private LuaConsole _luaconsole = null;
public LuaConsole LuaConsole1 { get { if (_luaconsole == null) _luaconsole = new LuaConsole(); return _luaconsole; } set { _luaconsole = value; } }
@ -1575,8 +1579,8 @@ namespace BizHawk.MultiClient
Global.OSD.AddMessage("Cheats file loaded");
}
}
if (_cheats != null) Cheats1.UpdateValues();
Cheats_UpdateValues();
CurrentlyOpenRom = file.CanonicalFullPath;
HandlePlatformMenus();

View File

@ -334,7 +334,7 @@ namespace BizHawk.MultiClient
{
if (Global.Emulator is NES)
{
Cheat c = new Cheat { name = GameGenieCode.Text };
Cheat c = new Cheat { Name = GameGenieCode.Text };
if (String.IsNullOrWhiteSpace(AddressBox.Text))
{
@ -344,26 +344,26 @@ namespace BizHawk.MultiClient
{
return;
}
c.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
c.value = byte.Parse(ValueBox.Text, NumberStyles.HexNumber);
c.Address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
c.Value = byte.Parse(ValueBox.Text, NumberStyles.HexNumber);
if (!String.IsNullOrWhiteSpace(CompareBox.Text))
{
try
{
c.compare = byte.Parse(CompareBox.Text, NumberStyles.HexNumber);
c.Compare = byte.Parse(CompareBox.Text, NumberStyles.HexNumber);
}
catch
{
c.compare = null;
c.Compare = null;
}
}
else
{
c.compare = null;
c.Compare = null;
}
c.domain = Global.Emulator.MemoryDomains[1]; //System Bus only
c.Domain = Global.Emulator.MemoryDomains[1]; //System Bus only
c.Enable();
Global.MainForm.Cheats1.AddCheat(c);

View File

@ -295,34 +295,34 @@ namespace BizHawk.MultiClient
{
Cheat c = new Cheat();
if (cheatname.Text.Length > 0)
c.name = cheatname.Text;
c.Name = cheatname.Text;
else
{
Processing = true;
GGCodeMaskBox.TextMaskFormat = MaskFormat.IncludeLiterals;
c.name = GGCodeMaskBox.Text;
c.Name = GGCodeMaskBox.Text;
GGCodeMaskBox.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
Processing = false;
}
if (String.IsNullOrWhiteSpace(AddressBox.Text))
c.address = 0;
c.Address = 0;
else
{
c.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
c.address += 0x8000;
c.Address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
c.Address += 0x8000;
}
if (String.IsNullOrWhiteSpace(ValueBox.Text))
c.value = 0;
c.Value = 0;
else
c.value = (byte)(int.Parse(ValueBox.Text, NumberStyles.HexNumber));
c.Value = (byte)(int.Parse(ValueBox.Text, NumberStyles.HexNumber));
c.compare = null;
c.Compare = null;
for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
if (Global.Emulator.MemoryDomains[x].ToString() == "BUS")
{
c.domain = Global.Emulator.MemoryDomains[x];
c.Domain = Global.Emulator.MemoryDomains[x];
c.Enable();
Global.MainForm.Cheats1.AddCheat(c);
break;

View File

@ -4,31 +4,32 @@ namespace BizHawk.MultiClient
{
public class Cheat
{
public string name { get; set; }
public int address { get; set; }
public byte value { get; set; }
public byte? compare { get; set; }
public MemoryDomain domain { get; set; }
public string Name { get; set; }
public int Address { get; set; }
public byte Value { get; set; }
public byte? Compare { get; set; }
public MemoryDomain Domain { get; set; }
private bool enabled;
public Cheat()
{
name = "";
address = 0;
value = 0;
compare = null;
Name = "";
Address = 0;
Value = 0;
Compare = null;
enabled = false;
domain = new MemoryDomain("NULL", 1, Endian.Little, addr => 0, (a, v) => { });
Domain = new MemoryDomain("NULL", 1, Endian.Little, addr => 0, (a, v) => { });
}
public Cheat(Cheat c)
{
name = c.name;
address = c.address;
value = c.value;
Name = c.Name;
Address = c.Address;
Value = c.Value;
enabled = c.enabled;
domain = c.domain;
compare = c.compare;
Domain = c.Domain;
Compare = c.Compare;
if (enabled)
{
Enable();
@ -41,12 +42,12 @@ namespace BizHawk.MultiClient
public Cheat(string cname, int addr, byte val, bool e, MemoryDomain d, byte? comp = null)
{
name = cname;
address = addr;
value = val;
Name = cname;
Address = addr;
Value = val;
enabled = e;
domain = d;
compare = comp;
Domain = d;
Compare = comp;
if (enabled)
{
Enable();
@ -57,16 +58,24 @@ namespace BizHawk.MultiClient
}
}
public bool IsSeparator
{
get
{
return Address == -1; //TODO: make this a nullable instead
}
}
public void Enable()
{
enabled = true;
if (Global.Emulator is NES && domain == Global.Emulator.MemoryDomains[1])
if (Global.Emulator is NES && Domain == Global.Emulator.MemoryDomains[1])
{
(Global.Emulator as NES).ApplyGameGenie(address, value, compare);
(Global.Emulator as NES).ApplyGameGenie(Address, Value, Compare);
}
else
{
MemoryPulse.Add(domain, address, value, compare);
MemoryPulse.Add(Domain, Address, Value, Compare);
}
Global.MainForm.UpdateCheatStatus();
@ -81,19 +90,22 @@ namespace BizHawk.MultiClient
public void DisposeOfCheat()
{
if (Global.Emulator is NES && domain == Global.Emulator.MemoryDomains[1])
if (Global.Emulator is NES && Domain == Global.Emulator.MemoryDomains[1])
{
(Global.Emulator as NES).RemoveGameGenie(address);
(Global.Emulator as NES).RemoveGameGenie(Address);
}
else
{
MemoryPulse.Remove(domain, address);
MemoryPulse.Remove(Domain, Address);
}
}
public bool IsEnabled()
public bool IsEnabled
{
return enabled;
get
{
return enabled;
}
}
~Cheat()

View File

@ -7,10 +7,10 @@ using System.Windows.Forms;
namespace BizHawk.MultiClient
{
public class CheatList
public class CheatList : IEnumerable<Cheat>
{
public List<Cheat> cheatList = new List<Cheat>();
public string currentCheatFile = "";
private List<Cheat> cheatList = new List<Cheat>();
public string CurrentCheatFile = "";
public bool Changes = false;
public int Count { get { return cheatList.Count; } }
@ -22,7 +22,7 @@ namespace BizHawk.MultiClient
int cheatcount = 0;
using (StreamReader sr = file.OpenText())
{
if (!append) currentCheatFile = path;
if (!append) CurrentCheatFile = path;
string s;
@ -37,12 +37,12 @@ namespace BizHawk.MultiClient
if (s.Length < 6) continue;
Cheat c = new Cheat();
string temp = s.Substring(0, s.IndexOf('\t'));
c.address = int.Parse(temp, NumberStyles.HexNumber);
c.Address = int.Parse(temp, NumberStyles.HexNumber);
int y = s.IndexOf('\t') + 1;
s = s.Substring(y, s.Length - y); //Value
temp = s.Substring(0, 2);
c.value = byte.Parse(temp, NumberStyles.HexNumber);
c.Value = byte.Parse(temp, NumberStyles.HexNumber);
bool comparefailed = false; //adelikat: This is a hack for 1.0.6 to support .cht files made in previous versions before the compare value was implemented
y = s.IndexOf('\t') + 1;
@ -52,17 +52,17 @@ namespace BizHawk.MultiClient
{
if (temp == "N")
{
c.compare = null;
c.Compare = null;
}
else
{
c.compare = byte.Parse(temp, NumberStyles.HexNumber);
c.Compare = byte.Parse(temp, NumberStyles.HexNumber);
}
}
catch
{
comparefailed = true;
c.domain = SetDomain(temp);
c.Domain = SetDomain(temp);
}
if (!comparefailed)
@ -70,7 +70,7 @@ namespace BizHawk.MultiClient
y = s.IndexOf('\t') + 1;
s = s.Substring(y, s.Length - y); //Memory Domain
temp = s.Substring(0, s.IndexOf('\t'));
c.domain = SetDomain(temp);
c.Domain = SetDomain(temp);
}
y = s.IndexOf('\t') + 1;
@ -88,7 +88,7 @@ namespace BizHawk.MultiClient
y = s.IndexOf('\t') + 1;
s = s.Substring(y, s.Length - y); //Name
c.name = s;
c.Name = s;
cheatcount++;
cheatList.Add(c);
@ -141,21 +141,26 @@ namespace BizHawk.MultiClient
return Global.Emulator.MemoryDomains[0];
}
public IEnumerator<Cheat> GetEnumerator()
{
return cheatList.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public bool IsActiveCheat(MemoryDomain d, int address)
{
return cheatList.Any(t => t.address == address && t.domain.Name == d.Name);
return cheatList.Any(t => t.Address == address && t.Domain.Name == d.Name);
}
public Cheat GetCheat(MemoryDomain d, int address)
{
return cheatList.FirstOrDefault(x => x.address == address && x.domain.Name == d.Name);
}
public void RemoveCheat(MemoryDomain d, int address)
public void Remove(MemoryDomain d, int address)
{
for (int x = 0; x < cheatList.Count; x++)
{
if (cheatList[x].address == address && cheatList[x].domain.Name == d.Name)
if (cheatList[x].Address == address && cheatList[x].Domain.Name == d.Name)
{
cheatList.Remove(cheatList[x]);
}
@ -164,22 +169,22 @@ namespace BizHawk.MultiClient
Global.OSD.AddMessage("Cheat removed");
}
public void DisableAll()
{
foreach (Cheat c in cheatList)
{
c.Disable();
}
}
public string CheatsPath
{
get
{
string sysId = Global.Emulator.SystemId;
//Exceptions. TODO: There are more of these I'm sure
if (sysId == "SGX" || sysId == "PCECD")
{
sysId = "PCE";
}
PathEntry pathEntry = Global.Config.PathEntries[sysId, "Cheats"];
PathEntry pathEntry = Global.Config.PathEntries[Global.Emulator.SystemId, "Cheats"];
if (pathEntry == null)
{
pathEntry = Global.Config.PathEntries[sysId, "Base"];
pathEntry = Global.Config.PathEntries[Global.Emulator.SystemId, "Base"];
}
string path = pathEntry.Path;
@ -207,21 +212,21 @@ namespace BizHawk.MultiClient
foreach (Cheat t in cheatList)
{
str += FormatAddress(t.address) + "\t";
str += String.Format("{0:X2}", t.value) + "\t";
str += FormatAddress(t.Address) + "\t";
str += String.Format("{0:X2}", t.Value) + "\t";
if (t.compare == null)
if (t.Compare == null)
{
str += "N\t";
}
else
{
str += String.Format("{0:X2}", t.compare) + "\t";
str += String.Format("{0:X2}", t.Compare) + "\t";
}
str += t.domain.Name + "\t";
str += t.Domain.Name + "\t";
if (t.IsEnabled())
if (t.IsEnabled)
{
str += "1\t";
}
@ -230,7 +235,7 @@ namespace BizHawk.MultiClient
str += "0\t";
}
str += t.name + "\n";
str += t.Name + "\n";
}
sw.WriteLine(str);
@ -251,22 +256,25 @@ namespace BizHawk.MultiClient
{
if (Changes && cheatList.Count > 0)
{
if (currentCheatFile.Length == 0)
currentCheatFile = MakeDefaultFilename();
if (CurrentCheatFile.Length == 0)
CurrentCheatFile = DefaultFilename;
SaveCheatFile(Global.CheatList.currentCheatFile);
SaveCheatFile(Global.CheatList.CurrentCheatFile);
}
else if (cheatList.Count == 0 && currentCheatFile.Length > 0)
else if (cheatList.Count == 0 && CurrentCheatFile.Length > 0)
{
var file = new FileInfo(currentCheatFile);
var file = new FileInfo(CurrentCheatFile);
file.Delete();
}
}
}
public string MakeDefaultFilename()
public string DefaultFilename
{
return Path.Combine(Global.CheatList.CheatsPath, PathManager.FilesystemSafeName(Global.Game) + ".cht");
get
{
return Path.Combine(Global.CheatList.CheatsPath, PathManager.FilesystemSafeName(Global.Game) + ".cht");
}
}
private int GetNumDigits(Int32 i)
@ -282,7 +290,7 @@ namespace BizHawk.MultiClient
/// </summary>
public bool AttemptLoadCheatFile()
{
string CheatFile = MakeDefaultFilename();
string CheatFile = DefaultFilename;
var file = new FileInfo(CheatFile);
if (file.Exists == false)
@ -314,11 +322,11 @@ namespace BizHawk.MultiClient
Global.MainForm.UpdateCheatStatus();
}
public void Remove(MemoryDomain domain, int address)
public void RemoveCheat(MemoryDomain domain, int address)
{
for (int x = 0; x < cheatList.Count; x++)
{
if (cheatList[x].domain == domain && cheatList[x].address == address)
if (cheatList[x].Domain == domain && cheatList[x].Address == address)
{
MemoryPulse.Remove(domain, address);
cheatList.Remove(cheatList[x]);
@ -328,17 +336,19 @@ namespace BizHawk.MultiClient
public void Add(Cheat c)
{
if (c == null)
if (c != null)
{
return;
cheatList.Add(c);
Global.MainForm.UpdateCheatStatus();
}
cheatList.Add(c);
Global.MainForm.UpdateCheatStatus();
}
public Cheat Cheat(int index)
public Cheat this[int index]
{
return cheatList[index];
get
{
return cheatList[index];
}
}
public void Insert(int index, Cheat item)
@ -349,7 +359,22 @@ namespace BizHawk.MultiClient
public bool HasActiveCheats
{
get { return cheatList.Any(t => t.IsEnabled()); }
get { return cheatList.Any(t => t.IsEnabled); }
}
public int ActiveCheatCount
{
get
{
if (HasActiveCheats)
{
return cheatList.Where(x => x.IsEnabled).Count();
}
else
{
return 0;
}
}
}
}
}

View File

@ -73,11 +73,11 @@ namespace BizHawk.MultiClient
{
if (index < Global.CheatList.Count)
{
if (Global.CheatList.Cheat(index).address < 0)
if (Global.CheatList[index].Address < 0)
{
color = Color.DarkGray;
}
else if (Global.CheatList.Cheat(index).IsEnabled())
else if (Global.CheatList[index].IsEnabled)
{
color = Color.LightCyan;
}
@ -91,47 +91,47 @@ namespace BizHawk.MultiClient
private void CheatListView_QueryItemText(int index, int column, out string text)
{
text = "";
if (Global.CheatList.Cheat(index).address == -1) //Separator
if (Global.CheatList[index].IsSeparator)
{
return;
}
else if (column == 0) //Name
{
text = Global.CheatList.Cheat(index).name;
text = Global.CheatList[index].Name;
}
else if (column == 1) //Address
{
text = Global.CheatList.FormatAddress(Global.CheatList.Cheat(index).address);
text = Global.CheatList.FormatAddress(Global.CheatList[index].Address);
}
else if (column == 2) //Value
{
if (Global.Config.Cheats_ValuesAsHex)
{
text = String.Format("{0:X2}", Global.CheatList.Cheat(index).value);
text = String.Format("{0:X2}", Global.CheatList[index].Value);
}
else
{
text = Global.CheatList.Cheat(index).value.ToString();
text = Global.CheatList[index].Value.ToString();
}
}
else if (column == 3) //Compare
{
if (Global.Config.Cheats_ValuesAsHex)
{
text = String.Format("{0:X2}", Global.CheatList.Cheat(index).compare);
text = String.Format("{0:X2}", Global.CheatList[index].Compare);
}
else
{
text = Global.CheatList.Cheat(index).compare.ToString();
text = Global.CheatList[index].Compare.ToString();
}
}
else if (column == 4) //Domain
{
text = Global.CheatList.Cheat(index).domain.Name;
text = Global.CheatList[index].Domain.Name;
}
else if (column == 5) //Enabled
{
if (Global.CheatList.Cheat(index).IsEnabled())
if (Global.CheatList[index].IsEnabled)
{
text = "*";
}
@ -221,7 +221,7 @@ namespace BizHawk.MultiClient
{
Changes();
Global.CheatList.RemoveCheat(c.domain, c.address);
Global.CheatList.Remove(c.Domain, c.Address);
Global.OSD.AddMessage("Cheat removed.");
if (!IsHandleCreated || IsDisposed) return;
@ -360,8 +360,8 @@ namespace BizHawk.MultiClient
if (indexes.Count == 0) return;
foreach (int index in indexes)
{
Cheat temp = Global.CheatList.Cheat(index);
Global.CheatList.Remove(Global.CheatList.Cheat(index));
Cheat temp = Global.CheatList[index];
Global.CheatList.Remove(Global.CheatList[index]);
Global.CheatList.Insert(index - 1, temp);
//Note: here it will get flagged many times redundantly potentially,
@ -389,14 +389,12 @@ namespace BizHawk.MultiClient
if (indexes.Count == 0) return;
foreach (int index in indexes)
{
Cheat temp = Global.CheatList.Cheat(index);
Cheat temp = Global.CheatList[index];
if (index < Global.CheatList.Count - 1)
{
Global.CheatList.Remove(Global.CheatList.Cheat(index));
Global.CheatList.Remove(Global.CheatList[index]);
Global.CheatList.Insert(index + 1, temp);
}
//Note: here it will get flagged many times redundantly potnetially,
@ -440,14 +438,14 @@ namespace BizHawk.MultiClient
void Changes()
{
Global.CheatList.Changes = true;
MessageLabel.Text = Path.GetFileName(Global.CheatList.currentCheatFile) + " *";
MessageLabel.Text = Path.GetFileName(Global.CheatList.CurrentCheatFile) + " *";
}
private FileInfo GetSaveFileFromUser()
{
var sfd = new SaveFileDialog();
if (Global.CheatList.currentCheatFile.Length > 0)
sfd.FileName = Path.GetFileNameWithoutExtension(Global.CheatList.currentCheatFile);
if (Global.CheatList.CurrentCheatFile.Length > 0)
sfd.FileName = Path.GetFileNameWithoutExtension(Global.CheatList.CurrentCheatFile);
else if (!(Global.Emulator is NullEmulator))
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
sfd.InitialDirectory = Global.CheatList.CheatsPath;
@ -469,9 +467,9 @@ namespace BizHawk.MultiClient
if (file != null)
{
Global.CheatList.SaveCheatFile(file.FullName);
Global.CheatList.currentCheatFile = file.FullName;
MessageLabel.Text = Path.GetFileName(Global.CheatList.currentCheatFile) + " saved.";
Global.Config.RecentCheats.Add(Global.CheatList.currentCheatFile);
Global.CheatList.CurrentCheatFile = file.FullName;
MessageLabel.Text = Path.GetFileName(Global.CheatList.CurrentCheatFile) + " saved.";
Global.Config.RecentCheats.Add(Global.CheatList.CurrentCheatFile);
}
}
@ -489,12 +487,12 @@ namespace BizHawk.MultiClient
if (result == DialogResult.Yes)
{
//TOOD: Do quicksave if filename, else save as
if (String.CompareOrdinal(Global.CheatList.currentCheatFile, "") == 0)
if (String.CompareOrdinal(Global.CheatList.CurrentCheatFile, "") == 0)
{
SaveAs();
}
else
Global.CheatList.SaveCheatFile(Global.CheatList.currentCheatFile);
Global.CheatList.SaveCheatFile(Global.CheatList.CurrentCheatFile);
return true;
}
else if (result == DialogResult.No)
@ -514,7 +512,7 @@ namespace BizHawk.MultiClient
{
Global.CheatList.Clear();
DisplayCheatsList();
Global.CheatList.currentCheatFile = "";
Global.CheatList.CurrentCheatFile = "";
Global.CheatList.Changes = false;
MessageLabel.Text = "";
}
@ -537,13 +535,13 @@ namespace BizHawk.MultiClient
private void Save()
{
if (string.Compare(Global.CheatList.currentCheatFile, "") == 0)
if (String.IsNullOrEmpty(Global.CheatList.CurrentCheatFile))
{
Global.CheatList.currentCheatFile = Global.CheatList.MakeDefaultFilename();
Global.CheatList.CurrentCheatFile = Global.CheatList.DefaultFilename;
}
Global.CheatList.SaveCheatFile(Global.CheatList.currentCheatFile);
MessageLabel.Text = Path.GetFileName(Global.CheatList.currentCheatFile) + " saved.";
Global.CheatList.SaveCheatFile(Global.CheatList.CurrentCheatFile);
MessageLabel.Text = Path.GetFileName(Global.CheatList.CurrentCheatFile) + " saved.";
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
@ -559,8 +557,8 @@ namespace BizHawk.MultiClient
private FileInfo GetFileFromUser()
{
var ofd = new OpenFileDialog();
if (Global.CheatList.currentCheatFile.Length > 0)
ofd.FileName = Path.GetFileNameWithoutExtension(Global.CheatList.currentCheatFile);
if (Global.CheatList.CurrentCheatFile.Length > 0)
ofd.FileName = Path.GetFileNameWithoutExtension(Global.CheatList.CurrentCheatFile);
ofd.InitialDirectory = Global.CheatList.CheatsPath;
ofd.Filter = "Cheat Files (*.cht)|*.cht|All Files|*.*";
ofd.RestoreDirectory = true;
@ -581,7 +579,7 @@ namespace BizHawk.MultiClient
{
Global.CheatList.LoadCheatFile(path, append);
UpdateNumberOfCheats();
MessageLabel.Text = Path.GetFileName(Global.CheatList.currentCheatFile);
MessageLabel.Text = Path.GetFileName(Global.CheatList.CurrentCheatFile);
DisplayCheatsList();
return true;
}
@ -615,7 +613,7 @@ namespace BizHawk.MultiClient
private void InsertSeparator()
{
Changes();
Cheat c = new Cheat {address = -1};
Cheat c = new Cheat {Address = -1};
ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices;
if (indexes.Count > 0)
@ -650,21 +648,21 @@ namespace BizHawk.MultiClient
return null;
}
Cheat c = new Cheat {name = NameBox.Text};
Cheat c = new Cheat {Name = NameBox.Text};
try
{
c.address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
c.value = (byte)(int.Parse(ValueBox.Text, Global.Config.Cheats_ValuesAsHex ? NumberStyles.HexNumber : NumberStyles.Integer));
c.Address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
c.Value = (byte)(int.Parse(ValueBox.Text, Global.Config.Cheats_ValuesAsHex ? NumberStyles.HexNumber : NumberStyles.Integer));
if (String.IsNullOrWhiteSpace(CompareBox.Text))
{
c.compare = null;
c.Compare = null;
}
else
{
c.compare = (byte)(int.Parse(CompareBox.Text, Global.Config.Cheats_ValuesAsHex ? NumberStyles.HexNumber : NumberStyles.Integer));
c.Compare = (byte)(int.Parse(CompareBox.Text, Global.Config.Cheats_ValuesAsHex ? NumberStyles.HexNumber : NumberStyles.Integer));
}
c.domain = Global.Emulator.MemoryDomains[DomainComboBox.SelectedIndex];
c.Domain = Global.Emulator.MemoryDomains[DomainComboBox.SelectedIndex];
c.Enable();
}
catch
@ -693,7 +691,7 @@ namespace BizHawk.MultiClient
{
foreach (int index in indexes)
{
Global.CheatList.Remove(Global.CheatList.Cheat(indexes[0])); //index[0] used since each iteration will make this the correct list index
Global.CheatList.Remove(Global.CheatList[indexes[0]]); //index[0] used since each iteration will make this the correct list index
}
indexes.Clear();
DisplayCheatsList();
@ -713,20 +711,21 @@ namespace BizHawk.MultiClient
private void UpdateNumberOfCheats()
{
string message = "";
int active = 0;
for (int x = 0; x < Global.CheatList.Count; x++)
{
if (Global.CheatList.Cheat(x).IsEnabled())
active++;
}
int active = Global.CheatList.ActiveCheatCount;
int c = Global.CheatList.Count;
if (c == 1)
{
message += c.ToString() + " cheat (" + active.ToString() + " active)";
}
else if (c == 0)
{
message += c.ToString() + " cheats";
}
else
{
message += c.ToString() + " cheats (" + active.ToString() + " active)";
}
NumCheatsLabel.Text = message;
}
@ -753,9 +752,9 @@ namespace BizHawk.MultiClient
{
Cheat c = new Cheat();
int x = indexes[0];
c.name = Global.CheatList.Cheat(x).name;
c.address = Global.CheatList.Cheat(x).address;
c.value = Global.CheatList.Cheat(x).value;
c.Name = Global.CheatList[x].Name;
c.Address = Global.CheatList[x].Address;
c.Value = Global.CheatList[x].Value;
Changes();
Global.CheatList.Add(c);
DisplayCheatsList();
@ -779,13 +778,15 @@ namespace BizHawk.MultiClient
{
for (int x = 0; x < indexes.Count; x++)
{
if (Global.CheatList.Cheat(indexes[x]).IsEnabled())
Global.CheatList.Cheat(indexes[x]).Disable();
if (Global.CheatList[indexes[x]].IsEnabled)
{
Global.CheatList[indexes[x]].Disable();
}
else
{
try
{
Global.CheatList.Cheat(indexes[x]).Enable();
Global.CheatList[indexes[x]].Enable();
}
catch
{
@ -828,12 +829,12 @@ namespace BizHawk.MultiClient
ListView.SelectedIndexCollection indexes = CheatListView.SelectedIndices;
if (indexes.Count > 0)
{
NameBox.Text = Global.CheatList.Cheat(indexes[0]).name;
AddressBox.Text = Global.CheatList.FormatAddress(Global.CheatList.Cheat(indexes[0]).address);
DoHexorInt(ValueBox, Global.CheatList.Cheat(indexes[0]).value);
DoHexorInt(CompareBox, Global.CheatList.Cheat(indexes[0]).compare);
NameBox.Text = Global.CheatList[indexes[0]].Name;
AddressBox.Text = Global.CheatList.FormatAddress(Global.CheatList[indexes[0]].Address);
DoHexorInt(ValueBox, Global.CheatList[indexes[0]].Value);
DoHexorInt(CompareBox, Global.CheatList[indexes[0]].Compare);
SetDomainSelection(Global.CheatList.Cheat(indexes[0]).domain.ToString());
SetDomainSelection(Global.CheatList[indexes[0]].Domain.ToString());
CheatListView.Refresh();
}
}
@ -845,7 +846,7 @@ namespace BizHawk.MultiClient
{
if (AddressBox.Text.Length > 0 && ValueBox.Text.Length > 0)
{
Global.CheatList.Remove(Global.CheatList.Cheat(indexes[0]));
Global.CheatList.Remove(Global.CheatList[indexes[0]]);
Global.CheatList.Add(MakeCheat());
Changes();
}
@ -946,7 +947,7 @@ namespace BizHawk.MultiClient
}
string Str = e.Label;
Global.CheatList.cheatList[e.Item].name = Str;
Global.CheatList[e.Item].Name = Str;
}
private void restoreWindowSizeToolStripMenuItem_Click(object sender, EventArgs e)
@ -1005,15 +1006,12 @@ namespace BizHawk.MultiClient
public void DisableAllCheats()
{
if (Global.CheatList.cheatList.Count > 0)
if (Global.CheatList.Any())
{
Global.OSD.AddMessage("All cheats disabled.");
}
foreach (Cheat t in Global.CheatList.cheatList)
{
t.Disable();
}
Global.CheatList.DisableAll();
MemoryPulse.Clear();
CheatListView.Refresh();
@ -1213,7 +1211,7 @@ namespace BizHawk.MultiClient
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
for (int x = 0; x < Global.CheatList.cheatList.Count; x++)
for (int x = 0; x < Global.CheatList.Count; x++)
{
CheatListView.SelectItem(x, true);
}
@ -1227,7 +1225,7 @@ namespace BizHawk.MultiClient
}
else if (e.KeyCode == Keys.A && e.Control && !e.Alt && !e.Shift) //Select All
{
for (int x = 0; x < Global.CheatList.cheatList.Count; x++)
for (int x = 0; x < Global.CheatList.Count; x++)
{
CheatListView.SelectItem(x, true);
}

View File

@ -835,14 +835,14 @@ namespace BizHawk.MultiClient
Global.MainForm.RamSearch1.UpdateValues();
Global.MainForm.RamWatch1.UpdateValues();
Global.MainForm.Cheats1.UpdateValues();
Global.MainForm.Cheats_UpdateValues();
}
private void UnFreezeAddress(int address)
{
if (address >= 0)
{
Cheat c = new Cheat {address = address, value = Domain.PeekByte(address), domain = Domain};
Cheat c = new Cheat {Address = address, Value = Domain.PeekByte(address), Domain = Domain};
Global.MainForm.Cheats1.RemoveCheat(c);
switch (DataSize)
@ -851,18 +851,18 @@ namespace BizHawk.MultiClient
case 1:
break;
case 2:
Cheat c2 = new Cheat {address = address + 1, domain = Domain, value = Domain.PeekByte(address + 1)};
Cheat c2 = new Cheat {Address = address + 1, Domain = Domain, Value = Domain.PeekByte(address + 1)};
c2.Enable();
Global.MainForm.Cheats1.RemoveCheat(c2);
break;
case 4:
Cheat c42 = new Cheat {address = address + 1, domain = Domain, value = Domain.PeekByte(address + 1)};
Cheat c42 = new Cheat {Address = address + 1, Domain = Domain, Value = Domain.PeekByte(address + 1)};
c42.Enable();
Global.MainForm.Cheats1.RemoveCheat(c42);
Cheat c43 = new Cheat {address = address + 2, domain = Domain, value = Domain.PeekByte(address + 2)};
Cheat c43 = new Cheat {Address = address + 2, Domain = Domain, Value = Domain.PeekByte(address + 2)};
c43.Enable();
Global.MainForm.Cheats1.RemoveCheat(c43);
Cheat c44 = new Cheat {address = address + 3, domain = Domain, value = Domain.PeekByte(address + 3)};
Cheat c44 = new Cheat {Address = address + 3, Domain = Domain, Value = Domain.PeekByte(address + 3)};
c44.Enable();
Global.MainForm.Cheats1.RemoveCheat(c44);
break;
@ -875,7 +875,7 @@ namespace BizHawk.MultiClient
{
if (address >= 0)
{
Cheat c = new Cheat {address = address, value = Domain.PeekByte(address), domain = Domain};
Cheat c = new Cheat {Address = address, Value = Domain.PeekByte(address), Domain = Domain};
c.Enable();
Global.MainForm.Cheats1.AddCheat(c);
@ -885,18 +885,18 @@ namespace BizHawk.MultiClient
case 1:
break;
case 2:
Cheat c2 = new Cheat {address = address + 1, domain = Domain, value = Domain.PeekByte(address + 1)};
Cheat c2 = new Cheat {Address = address + 1, Domain = Domain, Value = Domain.PeekByte(address + 1)};
c2.Enable();
Global.MainForm.Cheats1.AddCheat(c2);
break;
case 4:
Cheat c42 = new Cheat {address = address + 1, domain = Domain, value = Domain.PeekByte(address + 1)};
Cheat c42 = new Cheat {Address = address + 1, Domain = Domain, Value = Domain.PeekByte(address + 1)};
c42.Enable();
Global.MainForm.Cheats1.AddCheat(c42);
Cheat c43 = new Cheat {address = address + 2, domain = Domain, value = Domain.PeekByte(address + 2)};
Cheat c43 = new Cheat {Address = address + 2, Domain = Domain, Value = Domain.PeekByte(address + 2)};
c43.Enable();
Global.MainForm.Cheats1.AddCheat(c43);
Cheat c44 = new Cheat {address = address + 3, domain = Domain, value = Domain.PeekByte(address + 3)};
Cheat c44 = new Cheat {Address = address + 3, Domain = Domain, Value = Domain.PeekByte(address + 3)};
c44.Enable();
Global.MainForm.Cheats1.AddCheat(c44);
break;
@ -1194,11 +1194,11 @@ namespace BizHawk.MultiClient
for (int x = 0; x < Global.CheatList.Count; x++)
{
if (IsVisible(Global.CheatList.cheatList[x].address))
if (IsVisible(Global.CheatList[x].Address))
{
if (Domain.ToString() == Global.CheatList.cheatList[x].domain.ToString())
if (Domain.ToString() == Global.CheatList[x].Domain.ToString())
{
Rectangle rect = new Rectangle(GetAddressCoordinates(Global.CheatList.cheatList[x].address), new Size(15 * DataSize, fontHeight));
Rectangle rect = new Rectangle(GetAddressCoordinates(Global.CheatList[x].Address), new Size(15 * DataSize, fontHeight));
e.Graphics.DrawRectangle(new Pen(Brushes.Black), rect);
e.Graphics.FillRectangle(new SolidBrush(Global.Config.HexFreezeColor), rect);
}
@ -1641,7 +1641,7 @@ namespace BizHawk.MultiClient
Global.MainForm.RamSearch1.UpdateValues();
Global.MainForm.RamWatch1.UpdateValues();
Global.MainForm.Cheats1.UpdateValues();
Global.MainForm.Cheats_UpdateValues();
}
private void unfreezeAllToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -2289,7 +2289,7 @@ namespace BizHawk.MultiClient
UpdateValues();
Global.MainForm.HexEditor1.UpdateValues();
Global.MainForm.RamWatch1.UpdateValues();
Global.MainForm.Cheats1.UpdateValues();
Global.MainForm.Cheats_UpdateValues();
}
}
@ -2369,7 +2369,7 @@ namespace BizHawk.MultiClient
UpdateValues();
Global.MainForm.HexEditor1.UpdateValues();
Global.MainForm.RamWatch1.UpdateValues();
Global.MainForm.Cheats1.UpdateValues();
Global.MainForm.Cheats_UpdateValues();
}
}
@ -2723,7 +2723,7 @@ namespace BizHawk.MultiClient
Global.MainForm.RamWatch1.UpdateValues();
Global.MainForm.HexEditor1.UpdateValues();
Global.MainForm.Cheats1.UpdateValues();
Global.MainForm.Cheats_UpdateValues();
}
private void alwaysOnTopToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -1286,7 +1286,7 @@ namespace BizHawk.MultiClient
UpdateValues();
Global.MainForm.RamSearch1.UpdateValues();
Global.MainForm.HexEditor1.UpdateValues();
Global.MainForm.Cheats1.UpdateValues();
Global.MainForm.Cheats_UpdateValues();
}
private void UnfreezeAddress()
@ -1317,7 +1317,7 @@ namespace BizHawk.MultiClient
UpdateValues();
Global.MainForm.RamSearch1.UpdateValues();
Global.MainForm.HexEditor1.UpdateValues();
Global.MainForm.Cheats1.UpdateValues();
Global.MainForm.Cheats_UpdateValues();
}
private void freezeAddressToolStripMenuItem_Click(object sender, EventArgs e)
@ -1730,7 +1730,7 @@ namespace BizHawk.MultiClient
Global.MainForm.RamSearch1.UpdateValues();
Global.MainForm.HexEditor1.UpdateValues();
Global.MainForm.Cheats1.UpdateValues();
Global.MainForm.Cheats_UpdateValues();
}
private void WatchListView_SelectedIndexChanged(object sender, EventArgs e)