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

View File

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

View File

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

View File

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

View File

@ -10,7 +10,7 @@ namespace BizHawk.Client.ApiHawk
public sealed class MemApi : MemApiBase, IMem public sealed class MemApi : MemApiBase, IMem
{ {
private MemoryDomain _currentMemoryDomain; private MemoryDomain _currentMemoryDomain;
private bool _isBigEndian = false; private bool _isBigEndian;
public MemApi() public MemApi()
: base() : base()
{ {
@ -122,10 +122,8 @@ namespace BizHawk.Client.ApiHawk
data[i] = d.PeekByte(addr + i); data[i] = d.PeekByte(addr + i);
} }
using (var hasher = System.Security.Cryptography.SHA256.Create()) using var hasher = System.Security.Cryptography.SHA256.Create();
{ return hasher.ComputeHash(data).BytesToHexString();
return hasher.ComputeHash(data).BytesToHexString();
}
} }
#endregion #endregion
@ -134,14 +132,16 @@ namespace BizHawk.Client.ApiHawk
private int ReadSigned(long addr, int size, string domain = null) private int ReadSigned(long addr, int size, string domain = null)
{ {
if (_isBigEndian) return ReadSignedBig(addr, size, domain); return _isBigEndian
else return ReadSignedLittle(addr, size, domain); ? ReadSignedBig(addr, size, domain)
: ReadSignedLittle(addr, size, domain);
} }
private uint ReadUnsigned(long addr, int size, string domain = null) private uint ReadUnsigned(long addr, int size, string domain = null)
{ {
if (_isBigEndian) return ReadUnsignedBig(addr, size, domain); return _isBigEndian
else return ReadUnsignedLittle(addr, size, domain); ? ReadUnsignedBig(addr, size, domain)
: ReadUnsignedLittle(addr, size, domain);
} }
private void WriteSigned(long addr, int value, int size, string domain = null) 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)]; var d = string.IsNullOrEmpty(domain) ? Domain : DomainList[VerifyMemoryDomain(domain)];
if (d.CanPoke()) if (d.CanPoke())
{ {
for (var i = 0; i < memoryblock.Count; i++) foreach (var m in memoryblock)
{ {
if (addr < d.Size) if (addr < d.Size)
{ {
d.PokeByte(addr++, memoryblock[i]); d.PokeByte(addr++, m);
} }
else 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)]; var d = string.IsNullOrEmpty(domain) ? Domain : DomainList[VerifyMemoryDomain(domain)];
if (addr < d.Size) if (addr < d.Size)
{ {
var val = d.PeekUint(addr, bigendian); var val = d.PeekUint(addr, bigEndian);
var bytes = BitConverter.GetBytes(val); var bytes = BitConverter.GetBytes(val);
return BitConverter.ToSingle(bytes, 0); return BitConverter.ToSingle(bytes, 0);
} }
@ -212,7 +212,7 @@ namespace BizHawk.Client.ApiHawk
return 0; 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)]; var d = string.IsNullOrEmpty(domain) ? Domain : DomainList[VerifyMemoryDomain(domain)];
if (d.CanPoke()) if (d.CanPoke())
@ -222,7 +222,7 @@ namespace BizHawk.Client.ApiHawk
var dv = (float)value; var dv = (float)value;
var bytes = BitConverter.GetBytes(dv); var bytes = BitConverter.GetBytes(dv);
var v = BitConverter.ToUInt32(bytes, 0); var v = BitConverter.ToUInt32(bytes, 0);
d.PokeUint(addr, v, bigendian); d.PokeUint(addr, v, bigEndian);
} }
else else
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -30,7 +30,7 @@ namespace BizHawk.Client.ApiHawk
return JoypadButton.A; return JoypadButton.A;
case "B": case "B":
return JoypadButton.B; return JoypadButton.B;
case "B1": case "B1":
return JoypadButton.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/=FCEUX/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=feos/@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/=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/=Frameskip/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Frameskipping/@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/=Gameboy/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=gamedb/@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/=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/=Grafx/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=greenzone/@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> <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/=Hotkeys/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Intelli/@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/=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/=Libretro/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lightgun/@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> <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/=Pollable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=preload/@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/=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/=quicksave/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Regionable/@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> <s:Boolean x:Key="/Default/UserDictionary/Words/=resizer/@EntryIndexedValue">True</s:Boolean>