diff --git a/BizHawk.Client.EmuHawk/ToolAttributes.cs b/BizHawk.Client.EmuHawk/ToolAttributes.cs index fdec622477..93ccf61a03 100644 --- a/BizHawk.Client.EmuHawk/ToolAttributes.cs +++ b/BizHawk.Client.EmuHawk/ToolAttributes.cs @@ -1,16 +1,19 @@ using System; -using System.Drawing; +using System.Collections.Generic; namespace BizHawk.Client.EmuHawk { [AttributeUsage(AttributeTargets.Class)] public class ToolAttributes : Attribute { - public ToolAttributes(bool released) + public ToolAttributes(bool released, string[] supportedSystems) { Released = released; + SupportedSystems = supportedSystems; } public bool Released { get; private set; } + + public IEnumerable SupportedSystems { get; private set; } } } diff --git a/BizHawk.Client.EmuHawk/tools/AutoHawk.cs b/BizHawk.Client.EmuHawk/tools/AutoHawk.cs index 632a2f1198..fa56b6a20e 100644 --- a/BizHawk.Client.EmuHawk/tools/AutoHawk.cs +++ b/BizHawk.Client.EmuHawk/tools/AutoHawk.cs @@ -11,7 +11,7 @@ using BizHawk.Emulation.Common; namespace BizHawk.Client.EmuHawk { - [ToolAttributes(released: false)] + [ToolAttributes(released: false, supportedSystems: null)] public partial class AutoHawk : Form, IToolFormAutoConfig { public AutoHawk() diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs index 6f933ccd00..97eec314be 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs @@ -13,7 +13,6 @@ using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk { - [ToolAttributes(released: true)] public partial class GenericDebugger : Form, IToolFormAutoConfig, IControlMainform { public GenericDebugger() diff --git a/BizHawk.Client.EmuHawk/tools/GameShark.Designer.cs b/BizHawk.Client.EmuHawk/tools/GameShark.Designer.cs index cab983dccd..fdeafa3c3f 100644 --- a/BizHawk.Client.EmuHawk/tools/GameShark.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/GameShark.Designer.cs @@ -114,6 +114,7 @@ this.MaximizeBox = false; this.Name = "GameShark"; this.Text = "GameShark Converter"; + this.Load += new System.EventHandler(this.GameShark_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/BizHawk.Client.EmuHawk/tools/GameShark.cs b/BizHawk.Client.EmuHawk/tools/GameShark.cs index 0aeab18b0a..037f20ba34 100644 --- a/BizHawk.Client.EmuHawk/tools/GameShark.cs +++ b/BizHawk.Client.EmuHawk/tools/GameShark.cs @@ -8,16 +8,13 @@ using System.Globalization; namespace BizHawk.Client.EmuHawk { + [ToolAttributes(released: true, supportedSystems: new[] { "GB" })] public partial class GameShark : Form, IToolForm, IToolFormAutoConfig { //We are using Memory Domains, so we NEED this. [RequiredService] private IMemoryDomains MemoryDomains { get; set; } - //Since this is only using GameBoy at the moment, we do this. - //TODO: - //Expand this so that this tool supports ALL cores that are capable of using GameShark/CodeBreaker/Action Replay/Game Genie - [RequiredService] - private Gameboy GB { get; set; } + public GameShark() { InitializeComponent(); @@ -100,5 +97,10 @@ namespace BizHawk.Client.EmuHawk txtCheat.Clear(); txtDescription.Clear(); } + + private void GameShark_Load(object sender, EventArgs e) + { + + } } } diff --git a/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/BizHawk.Client.EmuHawk/tools/ToolManager.cs index 7695d18771..ddae18d945 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -43,10 +43,14 @@ namespace BizHawk.Client.EmuHawk public IToolForm Load(Type toolType, bool focus = true) { if (!typeof(IToolForm).IsAssignableFrom(toolType)) - throw new ArgumentException(String.Format("Type {0} does not implement IToolForm.", toolType.Name)); + { + throw new ArgumentException(string.Format("Type {0} does not implement IToolForm.", toolType.Name)); + } - if (!ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, toolType)) + if (!IsAvailable(toolType)) + { return null; + } var existingTool = _tools.FirstOrDefault(x => toolType.IsAssignableFrom(x.GetType())); @@ -63,6 +67,7 @@ namespace BizHawk.Client.EmuHawk existingTool.Show(); existingTool.Focus(); } + return existingTool; } } @@ -580,7 +585,37 @@ namespace BizHawk.Client.EmuHawk public bool IsAvailable(Type t) { - return ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, t); + if (!ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, t)) + { + return false; + } + + var tool = Assembly + .GetAssembly(typeof(IToolForm)) + .GetTypes() + .FirstOrDefault(type => type == t); + + if (tool == null) // This isn't a tool, must not be available + { + return false; + } + + var attr = tool.GetCustomAttributes(false) + .OfType() + .FirstOrDefault(); + + if (attr == null) // If no attributes there is no supported systems documented so assume all + { + return true; + } + + // If no supported systems mentioned assume all + if (attr.SupportedSystems != null && attr.SupportedSystems.Any()) + { + return attr.SupportedSystems.Contains(Global.Emulator.SystemId); + } + + return true; } // Eventually we want a single game genie tool, then this mess goes away