diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index cc6086634c..bb7aad8c59 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -24,6 +24,7 @@ namespace BizHawk.Client.EmuHawk /// /// A form designed to search through ram values /// + [RequiredServices(typeof(IMemoryDomains))] public partial class RamSearch : Form, IToolForm { // TODO: DoSearch grabs the state of widgets and passes it to the engine before running, so rip out code that is attempting to keep the state up to date through change events @@ -50,13 +51,13 @@ namespace BizHawk.Client.EmuHawk private bool _dropdownDontfire; // Used as a hack to get around lame .net dropdowns, there's no way to set their index without firing the selectedindexchanged event! - private IMemoryDomains _core; - public const int MaxDetailedSize = 1024 * 1024; // 1mb, semi-arbituary decision, sets the size to check for and automatically switch to fast mode for the user public const int MaxSupportedSize = 1024 * 1024 * 64; // 64mb, semi-arbituary decision, sets the maximum size ram search will support (as it will crash beyond this) public IDictionary EmulatorServices { private get; set; } + private IMemoryDomains Core { get { return (IMemoryDomains)EmulatorServices[typeof(IMemoryDomains)]; } } + public bool AskSaveChanges() { return true; @@ -71,7 +72,6 @@ namespace BizHawk.Client.EmuHawk public RamSearch() { - _core = (IMemoryDomains)Global.Emulator; // Cast is intentional, better to get a cast exception than a more amibious null reference exception later SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); @@ -84,9 +84,6 @@ namespace BizHawk.Client.EmuHawk _sortedColumn = string.Empty; _sortReverse = false; - _settings = new RamSearchEngine.Settings(_core); - _searches = new RamSearchEngine(_settings); - TopMost = Global.Config.RamSearchSettings.TopMost; } @@ -119,6 +116,9 @@ namespace BizHawk.Client.EmuHawk private void RamSearch_Load(object sender, EventArgs e) { + _settings = new RamSearchEngine.Settings(Core); + _searches = new RamSearchEngine(_settings); + ErrorIconButton.Visible = false; _dropdownDontfire = true; LoadConfigSettings(); @@ -126,7 +126,7 @@ namespace BizHawk.Client.EmuHawk SpecificValueBox.Type = _settings.Type; MessageLabel.Text = string.Empty; - SpecificAddressBox.MaxLength = (_core.MemoryDomains.MainMemory.Size - 1).NumHexDigits(); + SpecificAddressBox.MaxLength = (Core.MemoryDomains.MainMemory.Size - 1).NumHexDigits(); HardSetSizeDropDown(_settings.Size); PopulateTypeDropDown(); HardSetDisplayTypeDropDown(_settings.Type); @@ -296,8 +296,7 @@ namespace BizHawk.Client.EmuHawk Close(); } - _core = (IMemoryDomains)Global.Emulator; // Cast is intentional, better to get a cast exception than a more amibious null reference exception later - _settings.Domain = _core.MemoryDomains.MainMemory; + _settings.Domain = Core.MemoryDomains.MainMemory; MessageLabel.Text = "Search restarted"; DoDomainSizeCheck(); NewSearch(); @@ -590,7 +589,7 @@ namespace BizHawk.Client.EmuHawk private void SetMemoryDomain(string name) { - _settings.Domain = _core.MemoryDomains[name]; + _settings.Domain = Core.MemoryDomains[name]; SetReboot(true); SpecificAddressBox.MaxLength = (_settings.Domain.Size - 1).NumHexDigits(); DoDomainSizeCheck(); @@ -847,7 +846,7 @@ namespace BizHawk.Client.EmuHawk _currentFileName = file.FullName; } - var watches = new WatchList(_core, _settings.Domain); + var watches = new WatchList(Core, _settings.Domain); watches.Load(file.FullName, append); var watchList = watches.Where(x => !x.IsSeparator); @@ -1003,7 +1002,7 @@ namespace BizHawk.Client.EmuHawk { if (!string.IsNullOrWhiteSpace(_currentFileName)) { - var watches = new WatchList(_core, _settings.Domain) { CurrentFileName = _currentFileName }; + var watches = new WatchList(Core, _settings.Domain) { CurrentFileName = _currentFileName }; for (var i = 0; i < _searches.Count; i++) { watches.Add(_searches[i]); @@ -1031,7 +1030,7 @@ namespace BizHawk.Client.EmuHawk private void SaveAsMenuItem_Click(object sender, EventArgs e) { - var watches = new WatchList(_core, _settings.Domain) { CurrentFileName = _currentFileName }; + var watches = new WatchList(Core, _settings.Domain) { CurrentFileName = _currentFileName }; for (var i = 0; i < _searches.Count; i++) { watches.Add(_searches[i]); @@ -1070,7 +1069,7 @@ namespace BizHawk.Client.EmuHawk { MemoryDomainsSubMenu.DropDownItems.Clear(); MemoryDomainsSubMenu.DropDownItems.AddRange( - _core.MemoryDomains.MenuItems(SetMemoryDomain, _searches.Domain.Name, MaxSupportedSize) + Core.MemoryDomains.MenuItems(SetMemoryDomain, _searches.Domain.Name, MaxSupportedSize) .ToArray()); } @@ -1384,7 +1383,7 @@ namespace BizHawk.Client.EmuHawk { "DiffColumn", -1 }, }; - _settings = new RamSearchEngine.Settings(_core); + _settings = new RamSearchEngine.Settings(Core); if (_settings.Mode == RamSearchEngine.Settings.SearchMode.Fast) { SetToFastMode();