ApiHawk - Add few other system inputs
SNES, SMS, Genesis, N64, GB Following some tests, it works (so I'd say that this feature is beta)
This commit is contained in:
parent
e294e29202
commit
8cd88cdeca
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
|
||||
|
@ -22,6 +23,7 @@ namespace BizHawk.Client.ApiHawk
|
|||
private static readonly Assembly clientAssembly;
|
||||
private static readonly object clientMainFormInstance;
|
||||
private static readonly Type mainFormClass;
|
||||
private static readonly Array joypadButtonsArray = Enum.GetValues(typeof(JoypadButton));
|
||||
|
||||
internal static readonly BizHawkSystemIdToEnumConverter SystemIdConverter = new BizHawkSystemIdToEnumConverter();
|
||||
internal static readonly JoypadStringToEnumConverter JoypadConverter = new JoypadStringToEnumConverter();
|
||||
|
@ -120,16 +122,13 @@ namespace BizHawk.Client.ApiHawk
|
|||
/// <param name="bottom">Bottom padding</param>
|
||||
public static void SetExtraPadding(int left, int top, int right, int bottom)
|
||||
{
|
||||
Type emuLuaLib = clientAssembly.GetType("BizHawk.Client.EmuHawk.EmuHawkLuaLibrary");
|
||||
MethodInfo paddingMethod = emuLuaLib.GetMethod("SetClientExtraPadding");
|
||||
paddingMethod.Invoke(paddingMethod, new object[] { left, top, right, bottom });
|
||||
FieldInfo f = clientAssembly.GetType("BizHawk.Client.EmuHawk.GlobalWin").GetField("DisplayManager");
|
||||
object displayManager = f.GetValue(null);
|
||||
f = f.FieldType.GetField("ClientExtraPadding");
|
||||
f.SetValue(displayManager, new Padding(left, top, right, bottom));
|
||||
|
||||
/*FieldInfo f = clientAssembly.GetType("BizHawk.Client.EmuHawk.GlobalWin").GetField("DisplayManager").FieldType.GetField("ClientExtraPadding");
|
||||
f.SetValue(clientAssembly.GetType("BizHawk.Client.EmuHawk.GlobalWin").GetField("DisplayManager"), new System.Windows.Forms.Padding(left, top, right, bottom));
|
||||
MethodInfo resize = mainFormClass.GetMethod("FrameBufferResized");
|
||||
resize.Invoke(clientMainFormInstance, null);*/
|
||||
/*GlobalWin.DisplayManager.ClientExtraPadding = new System.Windows.Forms.Padding(left, top, right, bottom);
|
||||
GlobalWin.MainForm.FrameBufferResized();*/
|
||||
resize.Invoke(clientMainFormInstance, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -169,6 +168,7 @@ namespace BizHawk.Client.ApiHawk
|
|||
/// <param name="player">Player (one based) whom inputs must be set</param>
|
||||
/// <param name="joypad"><see cref="Joypad"/> with inputs</param>
|
||||
/// <exception cref="IndexOutOfRangeException">Raised when you specify a player less than 1 or greater than maximum allows (see SystemInfo class to get this information)</exception>
|
||||
/// <remarks>Still have some strange behaviour with multiple inputs; so this feature is still in beta</remarks>
|
||||
public static void SetInput(int player, Joypad joypad)
|
||||
{
|
||||
if (player < 1 || player > RunningSystem.MaxControllers)
|
||||
|
@ -184,16 +184,33 @@ namespace BizHawk.Client.ApiHawk
|
|||
}
|
||||
else
|
||||
{
|
||||
Parallel.ForEach<JoypadButton>((IEnumerable<JoypadButton>)Enum.GetValues(typeof(JoypadButton)), button =>
|
||||
foreach (JoypadButton button in joypadButtonsArray)
|
||||
{
|
||||
if (joypad.Inputs.HasFlag(button))
|
||||
{
|
||||
AutoFireStickyXorAdapter joypadAdaptor = Global.AutofireStickyXORAdapter;
|
||||
joypadAdaptor.SetSticky(string.Format("P{0} {1}", player, JoypadConverter.ConvertBack(button, RunningSystem)), true);
|
||||
if (RunningSystem == SystemInfo.GB)
|
||||
{
|
||||
joypadAdaptor.SetSticky(string.Format("{0}", JoypadConverter.ConvertBack(button, RunningSystem)), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
joypadAdaptor.SetSticky(string.Format("P{0} {1}", player, JoypadConverter.ConvertBack(button, RunningSystem)), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
//Using this break joypad usage (even in UI); have to figure out why
|
||||
/*if ((RunningSystem.AvailableButtons & JoypadButton.AnalogStick) == JoypadButton.AnalogStick)
|
||||
{
|
||||
AutoFireStickyXorAdapter joypadAdaptor = Global.AutofireStickyXORAdapter;
|
||||
for (int i = 1; i <= RunningSystem.MaxControllers; i++)
|
||||
{
|
||||
joypadAdaptor.SetFloat(string.Format("P{0} X Axis", i), allJoypads[i - 1].AnalogX);
|
||||
joypadAdaptor.SetFloat(string.Format("P{0} Y Axis", i), allJoypads[i - 1].AnalogY);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,7 +219,7 @@ namespace BizHawk.Client.ApiHawk
|
|||
/// Resume the emulation
|
||||
/// </summary>
|
||||
public static void UnpauseEmulation()
|
||||
{
|
||||
{
|
||||
MethodInfo method = mainFormClass.GetMethod("UnpauseEmulator");
|
||||
method.Invoke(clientMainFormInstance, null);
|
||||
}
|
||||
|
@ -228,15 +245,26 @@ namespace BizHawk.Client.ApiHawk
|
|||
Parallel.ForEach<string>(pressedButtons, button =>
|
||||
{
|
||||
int player;
|
||||
if (int.TryParse(button.Substring(1, 2), out player))
|
||||
if (RunningSystem == SystemInfo.GB)
|
||||
{
|
||||
allJoypads[player - 1].AddInput(JoypadConverter.Convert(button.Substring(3)));
|
||||
allJoypads[0].AddInput(JoypadConverter.Convert(button));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (int.TryParse(button.Substring(1, 2), out player))
|
||||
{
|
||||
allJoypads[player - 1].AddInput(JoypadConverter.Convert(button.Substring(3)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if ((RunningSystem.AvailableButtons & JoypadButton.AnalogStick) == JoypadButton.AnalogStick)
|
||||
{
|
||||
//joypadAdaptor.GetFloat();
|
||||
for (int i = 1; i <= RunningSystem.MaxControllers; i++)
|
||||
{
|
||||
allJoypads[i - 1].AnalogX = joypadAdaptor.GetFloat(string.Format("P{0} X Axis", i));
|
||||
allJoypads[i - 1].AnalogY = joypadAdaptor.GetFloat(string.Format("P{0} Y Axis", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ namespace BizHawk.Client.ApiHawk
|
|||
|
||||
private SystemInfo _System;
|
||||
private JoypadButton _PressedButtons;
|
||||
private float _AnalogX;
|
||||
private float _AnalogY;
|
||||
private int _Player;
|
||||
|
||||
#endregion
|
||||
|
@ -72,6 +74,38 @@ namespace BizHawk.Client.ApiHawk
|
|||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets X value for Analog stick
|
||||
/// </summary>
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets Y value for Analog stick
|
||||
/// </summary>
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets inputs
|
||||
/// If you pass inputs unavailable for current system, they'll be removed
|
||||
|
|
|
@ -30,7 +30,37 @@ namespace BizHawk.Client.ApiHawk
|
|||
return JoypadButton.A;
|
||||
|
||||
case "B":
|
||||
return JoypadButton.B;
|
||||
return JoypadButton.B;
|
||||
|
||||
case "B1":
|
||||
return JoypadButton.B1;
|
||||
|
||||
case "B2":
|
||||
return JoypadButton.B2;
|
||||
|
||||
case "C":
|
||||
return JoypadButton.C;
|
||||
|
||||
case "C UP":
|
||||
return JoypadButton.CUp;
|
||||
|
||||
case "C DOWN":
|
||||
return JoypadButton.CDown;
|
||||
|
||||
case "C LEFT":
|
||||
return JoypadButton.CLeft;
|
||||
|
||||
case "C RIGHT":
|
||||
return JoypadButton.CRight;
|
||||
|
||||
case "X":
|
||||
return JoypadButton.X;
|
||||
|
||||
case "Y":
|
||||
return JoypadButton.Y;
|
||||
|
||||
case "Z":
|
||||
return JoypadButton.Z;
|
||||
|
||||
case "START":
|
||||
return JoypadButton.Start;
|
||||
|
@ -39,17 +69,27 @@ namespace BizHawk.Client.ApiHawk
|
|||
return JoypadButton.Select;
|
||||
|
||||
case "UP":
|
||||
case "DPAD U":
|
||||
return JoypadButton.Up;
|
||||
|
||||
case "DOWN":
|
||||
case "DPAD D":
|
||||
return JoypadButton.Down;
|
||||
|
||||
case "LEFT":
|
||||
case "DPAD L":
|
||||
return JoypadButton.Left;
|
||||
|
||||
case "RIGHT":
|
||||
case "DPAD R":
|
||||
return JoypadButton.Right;
|
||||
|
||||
case "L":
|
||||
return JoypadButton.L;
|
||||
|
||||
case "R":
|
||||
return JoypadButton.R;
|
||||
|
||||
default:
|
||||
throw new IndexOutOfRangeException(string.Format("{0} is missing in convert list", value));
|
||||
}
|
||||
|
@ -87,6 +127,36 @@ namespace BizHawk.Client.ApiHawk
|
|||
case JoypadButton.B:
|
||||
return "B";
|
||||
|
||||
case JoypadButton.B1:
|
||||
return "B1";
|
||||
|
||||
case JoypadButton.B2:
|
||||
return "B2";
|
||||
|
||||
case JoypadButton.C:
|
||||
return "C";
|
||||
|
||||
case JoypadButton.CUp:
|
||||
return "C Up";
|
||||
|
||||
case JoypadButton.CDown:
|
||||
return "C Down";
|
||||
|
||||
case JoypadButton.CLeft:
|
||||
return "C Left";
|
||||
|
||||
case JoypadButton.CRight:
|
||||
return "C Right";
|
||||
|
||||
case JoypadButton.X:
|
||||
return "X";
|
||||
|
||||
case JoypadButton.Y:
|
||||
return "Y";
|
||||
|
||||
case JoypadButton.Z:
|
||||
return "Z";
|
||||
|
||||
case JoypadButton.Start:
|
||||
return "Start";
|
||||
|
||||
|
@ -94,16 +164,50 @@ namespace BizHawk.Client.ApiHawk
|
|||
return "Select";
|
||||
|
||||
case JoypadButton.Up:
|
||||
return "Up";
|
||||
if (((SystemInfo)parameter) == SystemInfo.N64)
|
||||
{
|
||||
return "Dpad U";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Up";
|
||||
}
|
||||
|
||||
case JoypadButton.Down:
|
||||
return "Down";
|
||||
if (((SystemInfo)parameter) == SystemInfo.N64)
|
||||
{
|
||||
return "Dpad D";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Down";
|
||||
}
|
||||
|
||||
case JoypadButton.Left:
|
||||
return "Left";
|
||||
if (((SystemInfo)parameter) == SystemInfo.N64)
|
||||
{
|
||||
return "Dpad L";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Left";
|
||||
}
|
||||
|
||||
case JoypadButton.Right:
|
||||
return "Right";
|
||||
if (((SystemInfo)parameter) == SystemInfo.N64)
|
||||
{
|
||||
return "Dpad R";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Right";
|
||||
}
|
||||
|
||||
case JoypadButton.L:
|
||||
return "L";
|
||||
|
||||
case JoypadButton.R:
|
||||
return "R";
|
||||
|
||||
default:
|
||||
throw new IndexOutOfRangeException(string.Format("{0} is missing in convert list", value));
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace BizHawk.Client.Common
|
|||
allSystemInfos.Add(new SystemInfo("Commodore 64", CoreSystem.Commodore64, 1));
|
||||
allSystemInfos.Add(new SystemInfo("ColecoVision", CoreSystem.ColecoVision, 1));
|
||||
allSystemInfos.Add(new SystemInfo("Gameboy Advance", CoreSystem.GameBoyAdvance, 1, StandardButtons | JoypadButton.L | JoypadButton.R));
|
||||
allSystemInfos.Add(new SystemInfo("Nintendo 64", CoreSystem.Nintendo64, 4, StandardButtons ^ JoypadButton.Select | JoypadButton.Z | JoypadButton.CUp | JoypadButton.CDown | JoypadButton.CLeft | JoypadButton.CRight | JoypadButton.AnalogStick));
|
||||
allSystemInfos.Add(new SystemInfo("Nintendo 64", CoreSystem.Nintendo64, 4, StandardButtons ^ JoypadButton.Select | JoypadButton.Z | JoypadButton.CUp | JoypadButton.CDown | JoypadButton.CLeft | JoypadButton.CRight | JoypadButton.AnalogStick | JoypadButton.L | JoypadButton.R));
|
||||
allSystemInfos.Add(new SystemInfo("Saturn", CoreSystem.Saturn, 2, UpDownLeftRight | JoypadButton.A | JoypadButton.B | JoypadButton.C | JoypadButton.X | JoypadButton.Y | JoypadButton.Z));
|
||||
allSystemInfos.Add(new SystemInfo("Game Boy Link", CoreSystem.DualGameBoy, 2, StandardButtons));
|
||||
allSystemInfos.Add(new SystemInfo("WonderSwan", CoreSystem.WonderSwan, 1));
|
||||
|
|
Loading…
Reference in New Issue