2013-04-14 23:56:45 +00:00
|
|
|
|
using BizHawk.Emulation.Consoles.Nintendo;
|
2011-03-16 03:56:22 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
2011-06-19 23:39:25 +00:00
|
|
|
|
public class Cheat
|
|
|
|
|
{
|
2013-08-25 04:23:27 +00:00
|
|
|
|
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; }
|
|
|
|
|
|
2011-06-19 23:39:25 +00:00
|
|
|
|
private bool enabled;
|
|
|
|
|
|
|
|
|
|
public Cheat()
|
|
|
|
|
{
|
2013-08-25 04:23:27 +00:00
|
|
|
|
Name = "";
|
|
|
|
|
Address = 0;
|
|
|
|
|
Value = 0;
|
|
|
|
|
Compare = null;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
enabled = false;
|
2013-08-25 04:23:27 +00:00
|
|
|
|
Domain = new MemoryDomain("NULL", 1, Endian.Little, addr => 0, (a, v) => { });
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Cheat(Cheat c)
|
|
|
|
|
{
|
2013-08-25 04:23:27 +00:00
|
|
|
|
Name = c.Name;
|
|
|
|
|
Address = c.Address;
|
|
|
|
|
Value = c.Value;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
enabled = c.enabled;
|
2013-08-25 04:23:27 +00:00
|
|
|
|
Domain = c.Domain;
|
|
|
|
|
Compare = c.Compare;
|
2011-08-06 19:49:21 +00:00
|
|
|
|
if (enabled)
|
2012-09-01 18:15:04 +00:00
|
|
|
|
{
|
|
|
|
|
Enable();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Disable();
|
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 11:59:14 +00:00
|
|
|
|
public Cheat(string cname, int addr, byte val, bool e, MemoryDomain d, byte? comp = null)
|
2011-06-19 23:39:25 +00:00
|
|
|
|
{
|
2013-08-25 04:23:27 +00:00
|
|
|
|
Name = cname;
|
|
|
|
|
Address = addr;
|
|
|
|
|
Value = val;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
enabled = e;
|
2013-08-25 04:23:27 +00:00
|
|
|
|
Domain = d;
|
|
|
|
|
Compare = comp;
|
2011-08-06 19:49:21 +00:00
|
|
|
|
if (enabled)
|
2012-08-31 11:59:14 +00:00
|
|
|
|
{
|
2012-09-01 18:15:04 +00:00
|
|
|
|
Enable();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Disable();
|
2012-08-31 11:59:14 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-25 04:23:27 +00:00
|
|
|
|
public bool IsSeparator
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Address == -1; //TODO: make this a nullable instead
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-19 23:39:25 +00:00
|
|
|
|
public void Enable()
|
|
|
|
|
{
|
|
|
|
|
enabled = true;
|
2013-08-25 04:23:27 +00:00
|
|
|
|
if (Global.Emulator is NES && Domain == Global.Emulator.MemoryDomains[1])
|
2012-09-01 14:13:36 +00:00
|
|
|
|
{
|
2013-08-25 04:23:27 +00:00
|
|
|
|
(Global.Emulator as NES).ApplyGameGenie(Address, Value, Compare);
|
2012-09-01 14:13:36 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-08-25 04:23:27 +00:00
|
|
|
|
MemoryPulse.Add(Domain, Address, Value, Compare);
|
2012-09-01 14:13:36 +00:00
|
|
|
|
}
|
2012-09-29 22:37:34 +00:00
|
|
|
|
|
|
|
|
|
Global.MainForm.UpdateCheatStatus();
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Disable()
|
|
|
|
|
{
|
|
|
|
|
enabled = false;
|
2012-09-01 14:35:12 +00:00
|
|
|
|
DisposeOfCheat();
|
2012-09-29 22:37:34 +00:00
|
|
|
|
Global.MainForm.UpdateCheatStatus();
|
2012-09-01 14:35:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisposeOfCheat()
|
|
|
|
|
{
|
2013-08-25 04:23:27 +00:00
|
|
|
|
if (Global.Emulator is NES && Domain == Global.Emulator.MemoryDomains[1])
|
2012-09-01 14:35:12 +00:00
|
|
|
|
{
|
2013-08-25 04:23:27 +00:00
|
|
|
|
(Global.Emulator as NES).RemoveGameGenie(Address);
|
2012-09-01 14:35:12 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-08-25 04:23:27 +00:00
|
|
|
|
MemoryPulse.Remove(Domain, Address);
|
2012-09-01 14:35:12 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-25 04:23:27 +00:00
|
|
|
|
public bool IsEnabled
|
2011-06-19 23:39:25 +00:00
|
|
|
|
{
|
2013-08-25 04:23:27 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return enabled;
|
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 01:16:55 +00:00
|
|
|
|
~Cheat()
|
|
|
|
|
{
|
2012-09-01 14:35:12 +00:00
|
|
|
|
DisposeOfCheat();
|
2011-08-07 01:16:55 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
2011-03-16 03:56:22 +00:00
|
|
|
|
}
|