Save/Load cheats now accounts for comparison type column

This commit is contained in:
Adam Sturge 2016-02-07 21:40:14 -08:00
parent 992acd9e96
commit 52c587d712
3 changed files with 32 additions and 49 deletions

View File

@ -23,25 +23,7 @@ namespace BizHawk.Client.Common
private COMPARISONTYPE _comparisonType; private COMPARISONTYPE _comparisonType;
public Cheat(Watch watch, int value, int? compare = null, bool enabled = true) public Cheat(Watch watch, int value, int? compare = null, bool enabled = true, COMPARISONTYPE comparisonType = COMPARISONTYPE.EQUAL)
{
_enabled = enabled;
_watch = watch;
_compare = compare;
_val = value;
Pulse();
}
/// <summary>
/// Adding second constructor for comparison type because I fear updating the method signiture for something in the Common namespace
/// </summary>
/// <param name="watch"></param>
/// <param name="value"></param>
/// <param name="comparisonType"></param>
/// <param name="compare"></param>
/// <param name="enabled"></param>
public Cheat(Watch watch, int value, COMPARISONTYPE comparisonType, int compare, bool enabled = true)
{ {
_enabled = enabled; _enabled = enabled;
_watch = watch; _watch = watch;
@ -297,10 +279,7 @@ namespace BizHawk.Client.Common
_watch.Poke(GetStringForPulse(_val)); _watch.Poke(GetStringForPulse(_val));
} }
break; break;
} }
} }
else else
{ {

View File

@ -397,6 +397,7 @@ namespace BizHawk.Client.Common
.Append(cheat.SizeAsChar).Append('\t') .Append(cheat.SizeAsChar).Append('\t')
.Append(cheat.TypeAsChar).Append('\t') .Append(cheat.TypeAsChar).Append('\t')
.Append((cheat.BigEndian ?? false) ? '1' : '0').Append('\t') .Append((cheat.BigEndian ?? false) ? '1' : '0').Append('\t')
.Append(cheat.ComparisonType.ToString()).Append('\t')
.AppendLine(); .AppendLine();
} }
} }
@ -450,6 +451,7 @@ namespace BizHawk.Client.Common
var size = WatchSize.Byte; var size = WatchSize.Byte;
var type = DisplayType.Hex; var type = DisplayType.Hex;
var bigendian = false; var bigendian = false;
Cheat.COMPARISONTYPE comparisonType = Cheat.COMPARISONTYPE.EQUAL;
if (s.Length < 6) if (s.Length < 6)
{ {
@ -481,6 +483,15 @@ namespace BizHawk.Client.Common
bigendian = vals[8] == "1"; bigendian = vals[8] == "1";
} }
// For backwards compatibility, don't assume these values exist
if (vals.Length > 8)
{
if(!Enum.TryParse<Cheat.COMPARISONTYPE>(vals[9], out comparisonType))
{
continue; //Not sure if this is the best answer, could just resort to ==
}
}
var watch = Watch.GenerateWatch( var watch = Watch.GenerateWatch(
domain, domain,
address, address,
@ -489,7 +500,7 @@ namespace BizHawk.Client.Common
bigendian, bigendian,
name); name);
Add(new Cheat(watch, value, compare, !Global.Config.DisableCheatsOnLoad && enabled)); Add(new Cheat(watch, value, compare, !Global.Config.DisableCheatsOnLoad && enabled, comparisonType));
} }
} }
catch catch

View File

@ -317,15 +317,6 @@ namespace BizHawk.Client.EmuHawk
NameBox.Text NameBox.Text
); );
if(CompareBox.ToRawInt() == null)
{
return new Cheat(
watch,
ValueBox.ToRawInt().Value
);
}
else
{
switch (CompareTypeDropDown.SelectedItem.ToString()) switch (CompareTypeDropDown.SelectedItem.ToString())
{ {
case "=": comparisonType = Cheat.COMPARISONTYPE.EQUAL; break; case "=": comparisonType = Cheat.COMPARISONTYPE.EQUAL; break;
@ -337,14 +328,16 @@ namespace BizHawk.Client.EmuHawk
default: comparisonType = Cheat.COMPARISONTYPE.EQUAL; break; default: comparisonType = Cheat.COMPARISONTYPE.EQUAL; break;
} }
int? c = CompareBox.ToRawInt() == null ? null : (int?)CompareBox.ToRawInt().Value;
return new Cheat( return new Cheat(
watch, watch,
ValueBox.ToRawInt().Value, ValueBox.ToRawInt().Value,
comparisonType, CompareBox.ToRawInt() == null ? null : (int?)CompareBox.ToRawInt().Value,
CompareBox.ToRawInt().Value true,
comparisonType
); );
}
} }
else else