ApiHawk - cleanups

This commit is contained in:
adelikat 2019-11-15 17:29:38 -06:00
parent 00952dedf7
commit cf4dd6770c
19 changed files with 133 additions and 357 deletions

View File

@ -3,20 +3,12 @@
namespace BizHawk.Client.ApiHawk
{
/// <summary>
/// This class hold logic interraction for the ExternalToolAttribute
/// This class holds logic interaction for the ExternalToolAttribute
/// This attribute helps BizHawk to handle ExternalTools
/// </summary>
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class BizHawkExternalToolAttribute : Attribute
{
#region Fields
private string _Name;
private string _Description;
private string _IconResourceName;
#endregion
#region cTor(s)
/// <summary>
@ -27,9 +19,9 @@ namespace BizHawk.Client.ApiHawk
/// <param name="iconResourceName">Icon embedded resource name</param>
public BizHawkExternalToolAttribute(string name, string description, string iconResourceName)
{
_Name = name;
_Description = description;
_IconResourceName = iconResourceName;
Name = name;
Description = description;
IconResourceName = iconResourceName;
}
/// <summary>
@ -56,36 +48,19 @@ namespace BizHawk.Client.ApiHawk
/// <summary>
/// Gets tool's friendly name
/// </summary>
public string Name
{
get
{
return _Name;
}
}
public string Name { get; }
/// <summary>
/// Gets tool's descriptino
/// Gets tool's description
/// </summary>
public string Description
{
get
{
return _Description;
}
}
public string Description { get; }
/// <summary>
/// Get the name of the embedded resource icon
/// </summary>
/// <remarks>Don't forget to set compile => Embedded reource to the icon file in your project</remarks>
public string IconResourceName
{
get
{
return _IconResourceName;
}
}
/// <remarks>Don't forget to set compile => Embedded resource to the icon file in your project</remarks>
public string IconResourceName { get; }
#endregion
}

View File

@ -3,20 +3,12 @@
namespace BizHawk.Client.ApiHawk
{
/// <summary>
/// This class hold logic interraction for the BizHawkExternalToolUsageAttribute
/// This class holds logic interaction for the BizHawkExternalToolUsageAttribute
/// This attribute helps ApiHawk to know how a tool can be enabled or not
/// </summary>
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class BizHawkExternalToolUsageAttribute : Attribute
{
#region Fields
private BizHawkExternalToolUsage _ToolUsage;
private CoreSystem _System;
private string _GameHash;
#endregion
#region cTor(s)
/// <summary>
@ -36,9 +28,9 @@ namespace BizHawk.Client.ApiHawk
throw new InvalidOperationException("A game hash must be set");
}
_ToolUsage = usage;
_System = system;
_GameHash = gameHash;
ToolUsage = usage;
System = system;
GameHash = gameHash;
}
/// <summary>
@ -63,37 +55,20 @@ namespace BizHawk.Client.ApiHawk
#region Properties
/// <summary>
/// Gets the specific system used by the exetrnal tool
/// Gets the specific system used by the external tool
/// </summary>
public CoreSystem System
{
get
{
return _System;
}
}
public CoreSystem System { get; }
/// <summary>
/// Gets the specific game (hash) used by the exetrnal tool
/// Gets the specific game (hash) used by the external tool
/// </summary>
public string GameHash
{
get
{
return _GameHash;
}
}
public string GameHash { get; }
/// <summary>
/// Gets the tool usage
/// </summary>
public BizHawkExternalToolUsage ToolUsage
{
get
{
return _ToolUsage;
}
}
public BizHawkExternalToolUsage ToolUsage { get; }
#endregion
}

View File

@ -10,9 +10,6 @@ namespace BizHawk.Client.ApiHawk
[OptionalService]
private IBoardInfo BoardInfo { get; set; }
public GameInfoApi()
{ }
public string GetRomName()
{
if (Global.Game != null)

View File

@ -7,34 +7,31 @@ namespace BizHawk.Client.ApiHawk
{
public sealed class JoypadApi : IJoypad
{
public JoypadApi()
{ }
public Dictionary<string,dynamic> Get(int? controller = null)
{
var buttons = new Dictionary<string, dynamic>();
var adaptor = Global.AutofireStickyXORAdapter;
foreach (var button in adaptor.Source.Definition.BoolButtons)
var adapter = Global.AutofireStickyXORAdapter;
foreach (var button in adapter.Source.Definition.BoolButtons)
{
if (!controller.HasValue)
{
buttons[button] = adaptor.IsPressed(button);
buttons[button] = adapter.IsPressed(button);
}
else if (button.Length >= 3 && button.Substring(0, 2) == $"P{controller}")
{
buttons[button.Substring(3)] = adaptor.IsPressed($"P{controller} {button.Substring(3)}");
buttons[button.Substring(3)] = adapter.IsPressed($"P{controller} {button.Substring(3)}");
}
}
foreach (var button in adaptor.Source.Definition.FloatControls)
foreach (var button in adapter.Source.Definition.FloatControls)
{
if (controller == null)
{
buttons[button] = adaptor.GetFloat(button);
buttons[button] = adapter.GetFloat(button);
}
else if (button.Length >= 3 && button.Substring(0, 2) == $"P{controller}")
{
buttons[button.Substring(3)] = adaptor.GetFloat($"P{controller} {button.Substring(3)}");
buttons[button.Substring(3)] = adapter.GetFloat($"P{controller} {button.Substring(3)}");
}
}
@ -49,14 +46,15 @@ namespace BizHawk.Client.ApiHawk
public Dictionary<string, dynamic> GetImmediate()
{
var buttons = new Dictionary<string, dynamic>();
var adaptor = Global.ActiveController;
foreach (var button in adaptor.Definition.BoolButtons)
var adapter = Global.ActiveController;
foreach (var button in adapter.Definition.BoolButtons)
{
buttons[button] = adaptor.IsPressed(button);
buttons[button] = adapter.IsPressed(button);
}
foreach (var button in adaptor.Definition.FloatControls)
foreach (var button in adapter.Definition.FloatControls)
{
buttons[button] = adaptor.GetFloat(button);
buttons[button] = adapter.GetFloat(button);
}
return buttons;
@ -116,7 +114,7 @@ namespace BizHawk.Client.ApiHawk
theValue = null;
}
var toPress = button.ToString();
var toPress = button;
if (controller.HasValue)
{
toPress = $"P{controller} {button}";
@ -178,21 +176,13 @@ namespace BizHawk.Client.ApiHawk
if (!string.IsNullOrWhiteSpace(theValueStr))
{
float f;
if (float.TryParse(theValueStr, out f))
if (float.TryParse(theValueStr, out var f))
{
theValue = f;
}
}
if (controller == null)
{
Global.StickyXORAdapter.SetFloat(name.ToString(), theValue);
}
else
{
Global.StickyXORAdapter.SetFloat($"P{controller} {name}", theValue);
}
Global.StickyXORAdapter.SetFloat(controller == null ? name : $"P{controller} {name}", theValue);
}
}
catch
@ -204,14 +194,9 @@ namespace BizHawk.Client.ApiHawk
{
try
{
if (controller == null)
{
Global.StickyXORAdapter.SetFloat(control, value);
}
else
{
Global.StickyXORAdapter.SetFloat($"P{controller} {control}", value);
}
Global.StickyXORAdapter.SetFloat(controller == null
? control
: $"P{controller} {control}", value);
}
catch
{

View File

@ -10,7 +10,7 @@ namespace BizHawk.Client.ApiHawk
public sealed class MemApi : MemApiBase, IMem
{
private MemoryDomain _currentMemoryDomain;
private bool _isBigEndian = false;
private bool _isBigEndian;
public MemApi()
: base()
{
@ -122,10 +122,8 @@ namespace BizHawk.Client.ApiHawk
data[i] = d.PeekByte(addr + i);
}
using (var hasher = System.Security.Cryptography.SHA256.Create())
{
return hasher.ComputeHash(data).BytesToHexString();
}
using var hasher = System.Security.Cryptography.SHA256.Create();
return hasher.ComputeHash(data).BytesToHexString();
}
#endregion
@ -134,14 +132,16 @@ namespace BizHawk.Client.ApiHawk
private int ReadSigned(long addr, int size, string domain = null)
{
if (_isBigEndian) return ReadSignedBig(addr, size, domain);
else return ReadSignedLittle(addr, size, domain);
return _isBigEndian
? ReadSignedBig(addr, size, domain)
: ReadSignedLittle(addr, size, domain);
}
private uint ReadUnsigned(long addr, int size, string domain = null)
{
if (_isBigEndian) return ReadUnsignedBig(addr, size, domain);
else return ReadUnsignedLittle(addr, size, domain);
return _isBigEndian
? ReadUnsignedBig(addr, size, domain)
: ReadUnsignedLittle(addr, size, domain);
}
private void WriteSigned(long addr, int value, int size, string domain = null)

View File

@ -179,11 +179,11 @@ namespace BizHawk.Client.ApiHawk
var d = string.IsNullOrEmpty(domain) ? Domain : DomainList[VerifyMemoryDomain(domain)];
if (d.CanPoke())
{
for (var i = 0; i < memoryblock.Count; i++)
foreach (var m in memoryblock)
{
if (addr < d.Size)
{
d.PokeByte(addr++, memoryblock[i]);
d.PokeByte(addr++, m);
}
else
{
@ -197,12 +197,12 @@ namespace BizHawk.Client.ApiHawk
}
}
protected float ReadFloat(long addr, bool bigendian, string domain = null)
protected float ReadFloat(long addr, bool bigEndian, string domain = null)
{
var d = string.IsNullOrEmpty(domain) ? Domain : DomainList[VerifyMemoryDomain(domain)];
if (addr < d.Size)
{
var val = d.PeekUint(addr, bigendian);
var val = d.PeekUint(addr, bigEndian);
var bytes = BitConverter.GetBytes(val);
return BitConverter.ToSingle(bytes, 0);
}
@ -212,7 +212,7 @@ namespace BizHawk.Client.ApiHawk
return 0;
}
protected void WriteFloat(long addr, double value, bool bigendian, string domain = null)
protected void WriteFloat(long addr, double value, bool bigEndian, string domain = null)
{
var d = string.IsNullOrEmpty(domain) ? Domain : DomainList[VerifyMemoryDomain(domain)];
if (d.CanPoke())
@ -222,7 +222,7 @@ namespace BizHawk.Client.ApiHawk
var dv = (float)value;
var bytes = BitConverter.GetBytes(dv);
var v = BitConverter.ToUInt32(bytes, 0);
d.PokeUint(addr, v, bigendian);
d.PokeUint(addr, v, bigEndian);
}
else
{

View File

@ -34,11 +34,9 @@ namespace BizHawk.Client.ApiHawk
{
var state = _memorySavestates[guid];
using (var ms = new MemoryStream(state))
using (var br = new BinaryReader(ms))
{
StatableCore.LoadStateBinary(br);
}
using var ms = new MemoryStream(state);
using var br = new BinaryReader(ms);
StatableCore.LoadStateBinary(br);
}
catch
{

View File

@ -1,6 +1,4 @@
using System;
using System.ComponentModel;
using BizHawk.Client.Common;
namespace BizHawk.Client.ApiHawk
@ -26,12 +24,9 @@ namespace BizHawk.Client.ApiHawk
public object Get(string key)
{
if (Global.UserBag.ContainsKey(key))
{
return Global.UserBag[key];
}
return null;
return Global.UserBag.ContainsKey(key)
? Global.UserBag[key]
: null;
}
public void Clear()

View File

@ -14,7 +14,7 @@ namespace BizHawk.Client.ApiHawk
/// <seealso cref="IExternalApiProvider"/>
public class BasicApiProvider : IExternalApiProvider
{
private readonly Dictionary<Type, IExternalApi> _Apis = new Dictionary<Type, IExternalApi>();
private readonly Dictionary<Type, IExternalApi> _apis = new Dictionary<Type, IExternalApi>();
public BasicApiProvider(IApiContainer container)
{
@ -25,7 +25,7 @@ namespace BizHawk.Client.ApiHawk
// this also fully allows apis that are not IExternalApi
var libs = container.Libraries;
_Apis = libs;
_apis = libs;
}
/// <summary>
@ -40,7 +40,7 @@ namespace BizHawk.Client.ApiHawk
throw new ArgumentNullException(nameof(api));
}
_Apis[typeof(T)] = api;
_apis[typeof(T)] = api;
}
public T GetApi<T>()
@ -51,8 +51,7 @@ namespace BizHawk.Client.ApiHawk
public object GetApi(Type t)
{
IExternalApi Api;
KeyValuePair<Type, IExternalApi>[] k = _Apis.Where(kvp => t.IsAssignableFrom(kvp.Key)).ToArray();
KeyValuePair<Type, IExternalApi>[] k = _apis.Where(kvp => t.IsAssignableFrom(kvp.Key)).ToArray();
if (k.Length > 0)
{
return k[0].Value;
@ -69,15 +68,9 @@ namespace BizHawk.Client.ApiHawk
public bool HasApi(Type t)
{
return _Apis.ContainsKey(t);
return _apis.ContainsKey(t);
}
public IEnumerable<Type> AvailableApis
{
get
{
return _Apis.Select(d => d.Key);
}
}
public IEnumerable<Type> AvailableApis => _apis.Select(d => d.Key);
}
}

View File

@ -236,7 +236,7 @@ namespace BizHawk.Client.ApiHawk
return "AmstradCPC";
default:
throw new IndexOutOfRangeException($"{value.ToString()} is missing in convert list");
throw new IndexOutOfRangeException($"{value} is missing in convert list");
}
}

View File

@ -16,7 +16,7 @@ namespace BizHawk.Client.ApiHawk
{
/// <summary>
/// This class contains some methods that
/// interract with BizHawk client
/// interact with BizHawk client
/// </summary>
public static class ClientApi
{
@ -46,11 +46,11 @@ namespace BizHawk.Client.ApiHawk
/// </summary>
public static event BeforeQuickSaveEventHandler BeforeQuickSave;
/// <summary>
/// Occurs when a ROM is succesfully loaded
/// Occurs when a ROM is successfully loaded
/// </summary>
public static event EventHandler RomLoaded;
/// <summary>
/// Occurs when a savestate is sucessfully loaded
/// Occurs when a savestate is successfully loaded
/// </summary>
public static event StateLoadedEventHandler StateLoaded;
/// <summary>
@ -63,7 +63,7 @@ namespace BizHawk.Client.ApiHawk
#region cTor(s)
/// <summary>
/// Static stuff initilization
/// Static stuff initialization
/// </summary>
static ClientApi()
{
@ -210,10 +210,7 @@ namespace BizHawk.Client.ApiHawk
/// <param name="stateName">User friendly name for saved state</param>
public static void OnStateLoaded(object sender, string stateName)
{
if (StateLoaded != null)
{
StateLoaded(sender, new StateLoadedEventArgs(stateName));
}
StateLoaded?.Invoke(sender, new StateLoadedEventArgs(stateName));
}
/// <summary>
@ -223,10 +220,7 @@ namespace BizHawk.Client.ApiHawk
/// <param name="stateName">User friendly name for saved state</param>
public static void OnStateSaved(object sender, string stateName)
{
if (StateSaved != null)
{
StateSaved(sender, new StateSavedEventArgs(stateName));
}
StateSaved?.Invoke(sender, new StateSavedEventArgs(stateName));
}
/// <summary>
@ -249,7 +243,7 @@ namespace BizHawk.Client.ApiHawk
/// <summary>
/// Save a state with specified name
/// </summary>
/// <param name="name">Savetate friendly name</param>
/// <param name="name">Savestate friendly name</param>
public static void SaveState(string name)
{
InvokeMainFormMethod("SaveState", new object[] { Path.Combine(PathManager.GetSaveStatePath(Global.Game), $"{name}.State"), name, false });
@ -417,10 +411,10 @@ namespace BizHawk.Client.ApiHawk
/// </summary>
private static void GetAllInputs()
{
AutoFireStickyXorAdapter joypadAdaptor = Global.AutofireStickyXORAdapter;
AutoFireStickyXorAdapter joypadAdapter = Global.AutofireStickyXORAdapter;
IEnumerable<string> pressedButtons = from button in joypadAdaptor.Definition.BoolButtons
where joypadAdaptor.IsPressed(button)
IEnumerable<string> pressedButtons = from button in joypadAdapter.Definition.BoolButtons
where joypadAdapter.IsPressed(button)
select button;
foreach (Joypad j in allJoypads)
@ -448,8 +442,8 @@ namespace BizHawk.Client.ApiHawk
{
for (int i = 1; i <= RunningSystem.MaxControllers; i++)
{
allJoypads[i - 1].AnalogX = joypadAdaptor.GetFloat($"P{i} X Axis");
allJoypads[i - 1].AnalogY = joypadAdaptor.GetFloat($"P{i} Y Axis");
allJoypads[i - 1].AnalogX = joypadAdapter.GetFloat($"P{i} X Axis");
allJoypads[i - 1].AnalogY = joypadAdapter.GetFloat($"P{i} Y Axis");
}
}
}
@ -652,7 +646,7 @@ namespace BizHawk.Client.ApiHawk
object osd = f.GetValue(null);
t = f.GetType();
MethodInfo m = t.GetMethod("AddMessage");
m.Invoke(osd, new Object[] { $"Window size set to {size}x" });
m.Invoke(osd, new object[] { $"Window size set to {size}x" });
}
else
{

View File

@ -7,62 +7,26 @@ namespace BizHawk.Client.ApiHawk.Classes.Events
/// </summary>
public sealed class BeforeQuickLoadEventArgs : EventArgs
{
#region Fields
private bool _Handled = false;
private string _QuickSaveSlotName;
#endregion
#region cTor(s)
internal BeforeQuickLoadEventArgs(string name)
{
_QuickSaveSlotName = name;
Name = name;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets value that defined if saved has been handled or not
/// </summary>
public bool Handled
{
get
{
return _Handled;
}
set
{
_Handled = value;
}
}
public bool Handled { get; set; }
/// <summary>
/// Gets quicksave name
/// </summary>
public string Name
{
get
{
return _QuickSaveSlotName;
}
}
public string Name { get; }
/// <summary>
/// Gets slot used for quicksave
/// </summary>
public int Slot
{
get
{
return int.Parse(_QuickSaveSlotName.Substring(_QuickSaveSlotName.Length - 1));
}
}
#endregion
public int Slot => int.Parse(Name.Substring(Name.Length - 1));
}
}

View File

@ -7,63 +7,25 @@ namespace BizHawk.Client.ApiHawk.Classes.Events
/// </summary>
public sealed class BeforeQuickSaveEventArgs : EventArgs
{
#region Fields
private bool _Handled = false;
private string _QuickSaveSlotName;
#endregion
#region cTor(s)
internal BeforeQuickSaveEventArgs(string name)
{
_QuickSaveSlotName = name;
Name = name;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets value that defined if saved has been handled or not
/// </summary>
public bool Handled
{
get
{
return _Handled;
}
set
{
_Handled = value;
}
}
public bool Handled { get; set; }
/// <summary>
/// Gets quicksave name
/// </summary>
public string Name
{
get
{
return _QuickSaveSlotName;
}
}
public string Name { get; }
/// <summary>
/// Gets slot used for quicksave
/// </summary>
public int Slot
{
get
{
return int.Parse(_QuickSaveSlotName.Substring(_QuickSaveSlotName.Length - 1));
}
}
#endregion
public int Slot => int.Parse(Name.Substring(Name.Length - 1));
}
}

View File

@ -7,38 +7,18 @@ namespace BizHawk.Client.ApiHawk.Classes.Events
/// </summary>
public sealed class StateLoadedEventArgs: EventArgs
{
#region Fields
string _Name;
#endregion
#region cTor(s)
/// <summary>
/// Initialize a new instance of <see cref="StateLoadedEventArgs"/>
/// </summary>
/// <param name="stateName">User friendly name of loaded state</param>
internal StateLoadedEventArgs(string stateName)
{
_Name = stateName;
Name = stateName;
}
#endregion
#region Properties
/// <summary>
/// Gets user friendly name of the loaded savestate
/// </summary>
public string Name
{
get
{
return _Name;
}
}
#endregion
public string Name { get; }
}
}

View File

@ -7,38 +7,18 @@ namespace BizHawk.Client.ApiHawk.Classes.Events
/// </summary>
public sealed class StateSavedEventArgs : EventArgs
{
#region Fields
string _Name;
#endregion
#region cTor(s)
/// <summary>
/// Initialize a new instance of <see cref="StateSavedEventArgs"/>
/// </summary>
/// <param name="stateName">User friendly name of loaded state</param>
internal StateSavedEventArgs(string stateName)
{
_Name = stateName;
Name = stateName;
}
#endregion
#region Properties
/// <summary>
/// Gets user friendly name of the loaded savestate
/// </summary>
public string Name
{
get
{
return _Name;
}
}
#endregion
public string Name { get; }
}
}

View File

@ -18,15 +18,15 @@ namespace BizHawk.Client.ApiHawk
{
#region Fields
private static FileSystemWatcher directoryMonitor;
private static List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
private static readonly FileSystemWatcher DirectoryMonitor;
private static readonly List<ToolStripMenuItem> MenuItems = new List<ToolStripMenuItem>();
#endregion
#region cTor(s)
/// <summary>
/// Initilization
/// Initialization
/// </summary>
static ExternalToolManager()
{
@ -34,12 +34,15 @@ namespace BizHawk.Client.ApiHawk
{
Directory.CreateDirectory(Global.Config.PathEntries["Global", "External Tools"].Path);
}
directoryMonitor = new FileSystemWatcher(Global.Config.PathEntries["Global", "External Tools"].Path, "*.dll");
directoryMonitor.IncludeSubdirectories = false;
directoryMonitor.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName;
directoryMonitor.Filter = "*.dll";
directoryMonitor.Created += new FileSystemEventHandler(DirectoryMonitor_Created);
directoryMonitor.EnableRaisingEvents = true;
DirectoryMonitor = new FileSystemWatcher(Global.Config.PathEntries["Global", "External Tools"].Path, "*.dll")
{
IncludeSubdirectories = false
, NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName
, Filter = "*.dll"
};
DirectoryMonitor.Created += DirectoryMonitor_Created;
DirectoryMonitor.EnableRaisingEvents = true;
ClientApi.RomLoaded += delegate { BuildToolStrip(); };
@ -51,18 +54,18 @@ namespace BizHawk.Client.ApiHawk
#region Methods
/// <summary>
/// Build the toolstrip menu
/// Build the ToolStrip menu
/// </summary>
private static void BuildToolStrip()
{
menuItems.Clear();
if (Directory.Exists(directoryMonitor.Path))
MenuItems.Clear();
if (Directory.Exists(DirectoryMonitor.Path))
{
DirectoryInfo dInfo = new DirectoryInfo(directoryMonitor.Path);
DirectoryInfo dInfo = new DirectoryInfo(DirectoryMonitor.Path);
foreach (FileInfo fi in dInfo.GetFiles("*.dll"))
{
menuItems.Add(GenerateToolTipFromFileName(fi.FullName));
MenuItems.Add(GenerateToolTipFromFileName(fi.FullName));
}
}
}
@ -78,20 +81,17 @@ namespace BizHawk.Client.ApiHawk
/// <remarks>For the moment, you could only load a dll that have a form (which implements <see cref="BizHawk.Client.EmuHawk.IExternalToolForm"/>)</remarks>
private static ToolStripMenuItem GenerateToolTipFromFileName(string fileName)
{
Type customFormType;
Assembly externalToolFile;
ToolStripMenuItem item = null;
try
{
BizHawk.Common.Win32Hacks.RemoveMOTW(fileName);
externalToolFile = Assembly.LoadFrom(fileName);
var externalToolFile = Assembly.LoadFrom(fileName);
object[] attributes = externalToolFile.GetCustomAttributes(typeof(BizHawkExternalToolAttribute), false);
if (attributes != null && attributes.Count() == 1)
{
BizHawkExternalToolAttribute attribute = (BizHawkExternalToolAttribute)attributes[0];
item = new ToolStripMenuItem(attribute.Name);
item.ToolTipText = attribute.Description;
item = new ToolStripMenuItem(attribute.Name) { ToolTipText = attribute.Description };
if (attribute.IconResourceName != "")
{
Stream s = externalToolFile.GetManifestResourceStream($"{externalToolFile.GetName().Name}.{attribute.IconResourceName}");
@ -101,7 +101,7 @@ namespace BizHawk.Client.ApiHawk
}
}
customFormType = externalToolFile.GetTypes().FirstOrDefault<Type>(t => t != null && t.FullName == "BizHawk.Client.EmuHawk.CustomMainForm");
var customFormType = externalToolFile.GetTypes().FirstOrDefault(t => t != null && t.FullName == "BizHawk.Client.EmuHawk.CustomMainForm");
if (customFormType == null)
{
item.ToolTipText = "Does not have a CustomMainForm";
@ -110,7 +110,7 @@ namespace BizHawk.Client.ApiHawk
item.Tag = fileName;
attributes = externalToolFile.GetCustomAttributes(typeof(BizHawkExternalToolUsageAttribute), false);
if (attributes != null && attributes.Count() == 1)
if (attributes != null && attributes.Length == 1)
{
BizHawkExternalToolUsageAttribute attribute2 = (BizHawkExternalToolUsageAttribute)attributes[0];
if(Global.Emulator.SystemId == "NULL" && attribute2.ToolUsage != BizHawkExternalToolUsage.Global)
@ -132,9 +132,10 @@ namespace BizHawk.Client.ApiHawk
}
else
{
item = new ToolStripMenuItem(externalToolFile.GetName().Name);
item.ToolTipText = "BizHawkExternalTool attribute hasn't been found";
item.Enabled = false;
item = new ToolStripMenuItem(externalToolFile.GetName().Name)
{
ToolTipText = "BizHawkExternalTool attribute hasn't been found", Enabled = false
};
}
}
catch (BadImageFormatException)
@ -144,7 +145,7 @@ namespace BizHawk.Client.ApiHawk
item.Enabled = false;
}
#if DEBUG //I added special debug stuff to get additionnal informations. Don(t think it can be usefull for released versions
#if DEBUG //I added special debug stuff to get additional information. Don't think it can be useful for released versions
catch (ReflectionTypeLoadException ex)
{
foreach (Exception e in ex.LoaderExceptions)
@ -174,7 +175,7 @@ namespace BizHawk.Client.ApiHawk
/// <param name="e">Event arguments</param>
private static void DirectoryMonitor_Created(object sender, FileSystemEventArgs e)
{
menuItems.Add(GenerateToolTipFromFileName(e.FullPath));
MenuItems.Add(GenerateToolTipFromFileName(e.FullPath));
}
#endregion
@ -185,13 +186,7 @@ namespace BizHawk.Client.ApiHawk
/// Gets a prebuild <see cref="ToolStripMenuItem"/>
/// This list auto-updated by the <see cref="ExternalToolManager"/> itself
/// </summary>
public static IEnumerable<ToolStripMenuItem> ToolStripMenu
{
get
{
return menuItems;
}
}
public static IEnumerable<ToolStripMenuItem> ToolStripMenu => MenuItems;
#endregion
}

View File

@ -80,14 +80,8 @@ namespace BizHawk.Client.ApiHawk
/// <remarks>The value you get will aways be rounded to 0 decimal</remarks>
public float AnalogX
{
get
{
return (float)Math.Round(_AnalogX, 0);
}
set
{
_AnalogX = value;
}
get => (float)Math.Round(_AnalogX, 0);
set => _AnalogX = value;
}
/// <summary>
@ -96,14 +90,8 @@ namespace BizHawk.Client.ApiHawk
/// <remarks>The value you get will aways be rounded to 0 decimal</remarks>
public float AnalogY
{
get
{
return (float)Math.Round(_AnalogY, 0);
}
set
{
_AnalogY = value;
}
get => (float)Math.Round(_AnalogY, 0);
set => _AnalogY = value;
}
/// <summary>
@ -113,10 +101,7 @@ namespace BizHawk.Client.ApiHawk
/// <remarks>It overrides all existing inputs</remarks>
public JoypadButton Inputs
{
get
{
return _PressedButtons;
}
get => _PressedButtons;
set
{
value &= _System.AvailableButtons;
@ -127,13 +112,7 @@ namespace BizHawk.Client.ApiHawk
/// <summary>
/// Gets <see cref="SystemInfo"/> for current <see cref="Joypad"/>
/// </summary>
public SystemInfo System
{
get
{
return _System;
}
}
public SystemInfo System => _System;
#endregion
}

View File

@ -30,7 +30,7 @@ namespace BizHawk.Client.ApiHawk
return JoypadButton.A;
case "B":
return JoypadButton.B;
return JoypadButton.B;
case "B1":
return JoypadButton.B1;

View File

@ -220,11 +220,13 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=FCEUX/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=feos/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Framebuffer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Framerate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Frameskip/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Frameskipping/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gameboy/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=gamedb/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=gamepad/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=gpgx/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Grafx/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=greenzone/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=greenzoned/@EntryIndexedValue">True</s:Boolean>
@ -234,6 +236,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Hotkeys/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Intelli/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=INTV/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Joypad/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Libretro/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lightgun/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lmsv/@EntryIndexedValue">True</s:Boolean>
@ -267,6 +270,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pollable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=preload/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Prereqs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=quickload/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=quicksave/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Regionable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=resizer/@EntryIndexedValue">True</s:Boolean>