Skip to content

Commit

Permalink
fix gamepad key injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Nov 3, 2022
1 parent 50d3a20 commit 9382283
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
10 changes: 0 additions & 10 deletions ControllerCommon/Utils/EnumUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,5 @@ public static T GetEnumValueFromDescription<T>(string description)
.Description == description).SingleOrDefault();
return field == null ? default(T) : (T)field.Field.GetRawConstantValue();
}

public static void AddFlag(byte main, byte flag)
{
main |= flag;
}

public static void RemoveFlag(byte main, byte flag)
{
main &= flag;
}
}
}
2 changes: 1 addition & 1 deletion ControllerService/Targets/DualShock4Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public override unsafe void UpdateReport(Gamepad Gamepad)
else if (Buttons.HasFlag(GamepadButtonFlagsExt.DPadLeft))
tempDPad = DualShock4DPadDirection.West;

if ((sState.wButtons & 0x0400) == 0x0400)
if (sState.wButtons.HasFlag(XInputStateButtons.Xbox))
tempSpecial |= DualShock4SpecialButton.Ps.Value;
if (Touch.OutputClickButton)
tempSpecial |= DualShock4SpecialButton.Touchpad.Value;
Expand Down
16 changes: 11 additions & 5 deletions ControllerService/Targets/ViGEmTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ namespace ControllerService.Targets
public abstract class ViGEmTarget : IDisposable
{
#region imports
protected enum XInputStateButtons : ushort
{
None = 0,
Xbox = 1024
}

[StructLayout(LayoutKind.Sequential)]
protected struct XInputStateSecret
{
public uint eventCount;
public ushort wButtons;
public XInputStateButtons wButtons;
public byte bLeftTrigger;
public byte bRightTrigger;
public short sThumbLX;
Expand Down Expand Up @@ -108,13 +114,13 @@ public void InjectReport(GamepadButtonFlagsExt buttons, ushort sButtons, bool Is
{
if(IsKeyDown)
{
ButtonsInjector |= Buttons;
sStateInjector.wButtons += sButtons;
ButtonsInjector |= buttons;
sStateInjector.wButtons |= (XInputStateButtons)sButtons;
}
else if (IsKeyUp)
{
ButtonsInjector &= Buttons;
sStateInjector.wButtons -= sButtons;
ButtonsInjector &= ~buttons;
sStateInjector.wButtons &= ~(XInputStateButtons)sButtons;
}
}

Expand Down
2 changes: 1 addition & 1 deletion ControllerService/Targets/Xbox360Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public override unsafe void UpdateReport(Gamepad Gamepad)
virtualController.SetButtonState(button, Buttons.HasFlag(value));
}

virtualController.SetButtonState(Xbox360Button.Guide, (sState.wButtons & 0x0400) == 0x0400);
virtualController.SetButtonState(Xbox360Button.Guide, sState.wButtons.HasFlag(XInputStateButtons.Xbox));

virtualController.SetSliderValue(Xbox360Slider.LeftTrigger, Gamepad.LeftTrigger);
virtualController.SetSliderValue(Xbox360Slider.RightTrigger, Gamepad.RightTrigger);
Expand Down

0 comments on commit 9382283

Please sign in to comment.