diff --git a/BizHawk.MultiClient/BizHawk.MultiClient.csproj b/BizHawk.MultiClient/BizHawk.MultiClient.csproj
index bb8ef1c295..2a2e7791bc 100644
--- a/BizHawk.MultiClient/BizHawk.MultiClient.csproj
+++ b/BizHawk.MultiClient/BizHawk.MultiClient.csproj
@@ -312,6 +312,7 @@
TI83KeyPad.cs
+
Form
diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs
index db24c8bdbf..5ca0082da9 100644
--- a/BizHawk.MultiClient/MainForm.cs
+++ b/BizHawk.MultiClient/MainForm.cs
@@ -24,7 +24,7 @@ namespace BizHawk.MultiClient
private RetainedViewportPanel retainedPanel;
public string CurrentlyOpenRom;
SavestateManager StateSlots = new SavestateManager();
-
+ public CheatList CheatList = new CheatList();
public bool PressFrameAdvance = false;
public bool PressRewind = false;
@@ -1805,6 +1805,7 @@ namespace BizHawk.MultiClient
{
if (!Cheats1.IsHandleCreated || Cheats1.IsDisposed)
{
+ Cheats1 = new Cheats();
Cheats1.Show();
}
else
diff --git a/BizHawk.MultiClient/tools/CheatList.cs b/BizHawk.MultiClient/tools/CheatList.cs
new file mode 100644
index 0000000000..36dc16bf1d
--- /dev/null
+++ b/BizHawk.MultiClient/tools/CheatList.cs
@@ -0,0 +1,116 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+using System.Globalization;
+using System.Windows.Forms;
+
+namespace BizHawk.MultiClient
+{
+ public class CheatList
+ {
+ public List cheatList = new List();
+ public string currentCheatFile = "";
+ public bool changes = false;
+
+ public bool LoadCheatFile(string path, bool append)
+ {
+ int y;
+ var file = new FileInfo(path);
+ if (file.Exists == false) return false;
+
+ using (StreamReader sr = file.OpenText())
+ {
+ if (!append) currentCheatFile = path;
+
+ string s = "";
+ string temp = "";
+
+ if (append == false)
+ cheatList.Clear(); //Wipe existing list and read from file
+
+ while ((s = sr.ReadLine()) != null)
+ {
+ if (s.Length < 6) continue;
+ Cheat c = new Cheat();
+ temp = s.Substring(0, s.IndexOf('\t')); //Address
+ c.address = int.Parse(temp, NumberStyles.HexNumber);
+
+ 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);
+
+ 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);
+
+ y = s.IndexOf('\t') + 1;
+ s = s.Substring(y, s.Length - y); //Enabled
+ y = int.Parse(s[0].ToString());
+
+ try
+ {
+ if (y == 0)
+ c.Disable();
+ else
+ c.Enable();
+ }
+ catch
+ {
+ NotSupportedError();
+ }
+
+ y = s.IndexOf('\t') + 1;
+ s = s.Substring(y, s.Length - y); //Name
+ c.name = s;
+
+ cheatList.Add(c);
+ }
+
+ Global.Config.RecentCheats.Add(file.FullName);
+ changes = false;
+
+
+ }
+
+ if (Global.Config.DisableCheatsOnLoad)
+ {
+ for (int x = 0; x < cheatList.Count; x++)
+ cheatList[x].Disable();
+ }
+ return true; //TODO
+ }
+
+ public void NotSupportedError()
+ {
+ MessageBox.Show("Unable to enable cheat for this platform, cheats are not supported for " + Global.Emulator.SystemId, "Cheat error",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ private MemoryDomain SetDomain(string name)
+ {
+ //Attempts to find the memory domain by name, if it fails, it defaults to index 0
+ for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
+ {
+ if (Global.Emulator.MemoryDomains[x].Name == name)
+ return Global.Emulator.MemoryDomains[x];
+ }
+ return Global.Emulator.MemoryDomains[0];
+ }
+
+ public bool IsActiveCheat(MemoryDomain d, int address)
+ {
+ for (int x = 0; x < cheatList.Count; x++)
+ {
+ if (cheatList[x].address == address && cheatList[x].domain.Name == d.Name)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+}
diff --git a/BizHawk.MultiClient/tools/Cheats.cs b/BizHawk.MultiClient/tools/Cheats.cs
index 2fcb3b6a3d..99ecc59cc8 100644
--- a/BizHawk.MultiClient/tools/Cheats.cs
+++ b/BizHawk.MultiClient/tools/Cheats.cs
@@ -29,6 +29,7 @@ namespace BizHawk.MultiClient
string currentCheatFile = "";
bool changes = false;
+ //TODO: Delete me
public List GetCheatList()
{
List c = new List();
@@ -51,7 +52,7 @@ namespace BizHawk.MultiClient
return false;
else
{
- LoadCheatFile(CheatFile, false);
+ Global.MainForm.CheatList.LoadCheatFile(CheatFile, false);
return true;
}
}
@@ -585,92 +586,18 @@ namespace BizHawk.MultiClient
return file;
}
- private MemoryDomain SetDomain(string name)
- {
- //Attempts to find the memory domain by name, if it fails, it defaults to index 0
- for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
- {
- if (Global.Emulator.MemoryDomains[x].Name == name)
- return Global.Emulator.MemoryDomains[x];
- }
- return Global.Emulator.MemoryDomains[0];
- }
+
public bool LoadCheatFile(string path, bool append)
{
- int y;
- var file = new FileInfo(path);
- if (file.Exists == false) return false;
-
- using (StreamReader sr = file.OpenText())
- {
- if (!append) currentCheatFile = path;
-
- string s = "";
- string temp = "";
-
- if (append == false)
- cheatList.Clear(); //Wipe existing list and read from file
-
- while ((s = sr.ReadLine()) != null)
- {
- if (s.Length < 6) continue;
- Cheat c = new Cheat();
- temp = s.Substring(0, s.IndexOf('\t')); //Address
- c.address = int.Parse(temp, NumberStyles.HexNumber);
-
- 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);
-
- 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);
-
- y = s.IndexOf('\t') + 1;
- s = s.Substring(y, s.Length - y); //Enabled
- y = int.Parse(s[0].ToString());
-
- try
- {
- if (y == 0)
- c.Disable();
- else
- c.Enable();
- }
- catch
- {
- NotSupportedError();
- }
-
- y = s.IndexOf('\t') + 1;
- s = s.Substring(y, s.Length - y); //Name
- c.name = s;
-
- cheatList.Add(c);
- }
-
- Global.Config.RecentCheats.Add(file.FullName);
- changes = false;
- MessageLabel.Text = Path.GetFileName(file.FullName);
- UpdateNumberOfCheats();
- }
-
- if (Global.Config.DisableCheatsOnLoad)
- {
- for (int x = 0; x < cheatList.Count; x++)
- cheatList[x].Disable();
- }
+ Global.MainForm.CheatList.LoadCheatFile(path, append);
+ UpdateNumberOfCheats();
+ MessageLabel.Text = Path.GetFileName(Global.MainForm.CheatList.currentCheatFile);
+ DisplayCheatsList();
return true; //TODO
}
- private void NotSupportedError()
- {
- MessageBox.Show("Unable to enable cheat for this platform, cheats are not supported for " + Global.Emulator.SystemId, "Cheat error",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
+
private void OpenCheatFile()
{
@@ -682,7 +609,6 @@ namespace BizHawk.MultiClient
if (r)
{
LoadCheatFile(file.FullName, false);
- DisplayCheatsList();
}
}
}
@@ -737,7 +663,7 @@ namespace BizHawk.MultiClient
c.Enable();
}
catch {
- NotSupportedError();
+ Global.MainForm.CheatList.NotSupportedError();
}
return c;
}
@@ -855,7 +781,7 @@ namespace BizHawk.MultiClient
}
catch
{
- NotSupportedError();
+ Global.MainForm.CheatList.NotSupportedError();
}
}
}
@@ -969,17 +895,7 @@ namespace BizHawk.MultiClient
CheatListView.Columns[4].Width = defaultOnWidth;
}
- public bool IsActiveCheat(MemoryDomain d, int address)
- {
- for (int x = 0; x < cheatList.Count; x++)
- {
- if (cheatList[x].address == address && cheatList[x].domain.Name == d.Name)
- {
- return true;
- }
- }
- return false;
- }
+
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
diff --git a/BizHawk.MultiClient/tools/RamSearch.cs b/BizHawk.MultiClient/tools/RamSearch.cs
index 9d9a90ccab..02d2505ee1 100644
--- a/BizHawk.MultiClient/tools/RamSearch.cs
+++ b/BizHawk.MultiClient/tools/RamSearch.cs
@@ -529,10 +529,10 @@ namespace BizHawk.MultiClient
if (!weededList.Contains(searchList[index]))
{
color = Color.Pink;
- if (Global.MainForm.Cheats1.IsActiveCheat(Domain, searchList[index].address))
+ if (Global.MainForm.CheatList.IsActiveCheat(Domain, searchList[index].address))
color = Color.Purple;
}
- else if (Global.MainForm.Cheats1.IsActiveCheat(Domain, searchList[index].address))
+ else if (Global.MainForm.CheatList.IsActiveCheat(Domain, searchList[index].address))
color = Color.LightCyan;
else
color = Color.White;
diff --git a/BizHawk.MultiClient/tools/RamWatch.cs b/BizHawk.MultiClient/tools/RamWatch.cs
index fc3f11a5e9..04df8c1f82 100644
--- a/BizHawk.MultiClient/tools/RamWatch.cs
+++ b/BizHawk.MultiClient/tools/RamWatch.cs
@@ -152,7 +152,7 @@ namespace BizHawk.MultiClient
{
if (watchList[index].type == atype.SEPARATOR)
color = this.BackColor;
- if (Global.MainForm.Cheats1.IsActiveCheat(Domain, watchList[index].address))
+ if (Global.MainForm.CheatList.IsActiveCheat(Domain, watchList[index].address))
color = Color.LightCyan;
}