From b378cd13e47b22044f54ab74c8ff447f29d23277 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 23 Mar 2014 15:58:44 +0000 Subject: [PATCH] Cheats - address issue 148, instead of throwing an exception when attempting to add an out of range address, present an error message. One odd side effect is that it will add a separator instead, but I think that's acceptable for now. --- .../tools/Cheats/CheatEdit.cs | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs b/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs index 88120afd63..3688e8004a 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/CheatEdit.cs @@ -271,19 +271,29 @@ namespace BizHawk.Client.EmuHawk { get { - var watch = Watch.GenerateWatch( - Global.Emulator.MemoryDomains[DomainDropDown.SelectedItem.ToString()], - AddressBox.ToRawInt().Value, - GetCurrentSize(), - Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString()), - NameBox.Text, - BigEndianCheckBox.Checked); + var domain = Global.Emulator.MemoryDomains[DomainDropDown.SelectedItem.ToString()]; + var address = AddressBox.ToRawInt().Value; + if (address < domain.Size) + { + var watch = Watch.GenerateWatch( + Global.Emulator.MemoryDomains[DomainDropDown.SelectedItem.ToString()], + AddressBox.ToRawInt().Value, + GetCurrentSize(), + Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString()), + NameBox.Text, + BigEndianCheckBox.Checked); - return new Cheat( - watch, - ValueBox.ToRawInt().Value, - CompareBox.ToRawInt() - ); + return new Cheat( + watch, + ValueBox.ToRawInt().Value, + CompareBox.ToRawInt() + ); + } + 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; + } } }