From 0213755d1641844d7068f8dcdfbae4d0e706b194 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 12 Nov 2016 09:00:11 -0600 Subject: [PATCH] Cheats - when editing a cheat's domain, if the address is out of range, don't update, rather than create a separator, fixes #539 --- .../tools/Cheats/CheatEdit.cs | 77 +++++++++---------- BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs | 13 +++- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs b/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs index 7f4003ff52..746f423e42 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs @@ -309,53 +309,50 @@ namespace BizHawk.Client.EmuHawk get { return _cheat; } } - public Cheat Cheat + public Cheat GetCheat() { - get + Cheat.COMPARISONTYPE comparisonType = Cheat.COMPARISONTYPE.NONE; + var domain = MemoryDomains[DomainDropDown.SelectedItem.ToString()]; + var address = AddressBox.ToRawInt().Value; + if (address < domain.Size) { - Cheat.COMPARISONTYPE comparisonType = Cheat.COMPARISONTYPE.NONE; - var domain = MemoryDomains[DomainDropDown.SelectedItem.ToString()]; - var address = AddressBox.ToRawInt().Value; - if (address < domain.Size) + var watch = Watch.GenerateWatch( + MemoryDomains[DomainDropDown.SelectedItem.ToString()], + AddressBox.ToRawInt().Value, + GetCurrentSize(), + Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString()), + BigEndianCheckBox.Checked, + NameBox.Text + ); + + switch (CompareTypeDropDown.SelectedItem.ToString()) { - var watch = Watch.GenerateWatch( - MemoryDomains[DomainDropDown.SelectedItem.ToString()], - AddressBox.ToRawInt().Value, - GetCurrentSize(), - Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString()), - BigEndianCheckBox.Checked, - NameBox.Text - ); + case "": comparisonType = Cheat.COMPARISONTYPE.NONE; break; + case "=": comparisonType = Cheat.COMPARISONTYPE.EQUAL; break; + case ">": comparisonType = Cheat.COMPARISONTYPE.GREATER_THAN; break; + case ">=": comparisonType = Cheat.COMPARISONTYPE.GREATER_THAN_OR_EQUAL; break; + case "<": comparisonType = Cheat.COMPARISONTYPE.LESS_THAN; break; + case "<=": comparisonType = Cheat.COMPARISONTYPE.LESS_THAN_OR_EQUAL; break; + case "!=": comparisonType = Cheat.COMPARISONTYPE.NOT_EQUAL; break; + default: comparisonType = Cheat.COMPARISONTYPE.NONE; break; + } - switch (CompareTypeDropDown.SelectedItem.ToString()) - { - case "": comparisonType = Cheat.COMPARISONTYPE.NONE; break; - case "=": comparisonType = Cheat.COMPARISONTYPE.EQUAL; break; - case ">": comparisonType = Cheat.COMPARISONTYPE.GREATER_THAN; break; - case ">=": comparisonType = Cheat.COMPARISONTYPE.GREATER_THAN_OR_EQUAL; break; - case "<": comparisonType = Cheat.COMPARISONTYPE.LESS_THAN; break; - case "<=": comparisonType = Cheat.COMPARISONTYPE.LESS_THAN_OR_EQUAL; break; - case "!=": comparisonType = Cheat.COMPARISONTYPE.NOT_EQUAL; break; - default: comparisonType = Cheat.COMPARISONTYPE.NONE; break; - } - - int? c = CompareBox.ToRawInt() == null ? null : (int?)CompareBox.ToRawInt().Value; + int? c = CompareBox.ToRawInt() == null ? null : (int?)CompareBox.ToRawInt().Value; - return new Cheat( - watch, - ValueBox.ToRawInt().Value, - CompareBox.ToRawInt() == null ? null : (int?)CompareBox.ToRawInt().Value, - true, - comparisonType - ); + return new Cheat( + watch, + ValueBox.ToRawInt().Value, + CompareBox.ToRawInt() == null ? null : (int?)CompareBox.ToRawInt().Value, + true, + comparisonType + ); - } - else - { - MessageBox.Show(address.ToString() + " is not a valid address for the domain " + domain.Name, "Index out of range", MessageBoxButtons.OK, MessageBoxIcon.Warning); - return Cheat.Separator; - } + } + else + { + MessageBox.Show(address.ToString() + " is not a valid address for the domain " + domain.Name, "Index out of range", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return Cheat.Separator; } } diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 63c6a1d221..1094dbf494 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -177,16 +177,21 @@ namespace BizHawk.Client.EmuHawk private void AddCheat() { - Global.CheatList.Add(CheatEditor.Cheat); + Global.CheatList.Add(CheatEditor.GetCheat()); UpdateDialog(); UpdateMessageLabel(); } private void EditCheat() { - Global.CheatList.Exchange(CheatEditor.OriginalCheat, CheatEditor.Cheat); - UpdateDialog(); - UpdateMessageLabel(); + var newCheat = CheatEditor.GetCheat(); + + if (!newCheat.IsSeparator) // If a separator comes from the cheat editor something must have been invalid + { + Global.CheatList.Exchange(CheatEditor.OriginalCheat, newCheat); + UpdateDialog(); + UpdateMessageLabel(); + } } public void SaveConfigSettings()