-
Notifications
You must be signed in to change notification settings - Fork 19
Add Riffmaster support for shadPS4 #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
faa48ef
b8e8e8c
448eb48
9921648
cb994c2
ab1d886
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||||||
| using System; | ||||||||||
| using Nefarius.ViGEm.Client.Targets; | ||||||||||
| using Nefarius.ViGEm.Client.Targets.Xbox360; | ||||||||||
| using RB4InstrumentMapper.Core.Parsing; | ||||||||||
|
|
||||||||||
| namespace RB4InstrumentMapper.Core.Mapping | ||||||||||
| { | ||||||||||
| /// <summary> | ||||||||||
| /// Maps Riffmaster guitar inputs to a ViGEmBus device with modifications to support shadPS4. | ||||||||||
| /// </summary> | ||||||||||
| internal class RiffmastershadPS4Mapper : ViGEmMapper | ||||||||||
| { | ||||||||||
| public RiffmastershadPS4Mapper(IBackendClient client) | ||||||||||
| : base(client) | ||||||||||
| { | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private static int currentPickup = 0; | ||||||||||
| private static bool pickupDown = false; | ||||||||||
|
|
||||||||||
| protected override XboxResult OnMessageReceived(byte command, ReadOnlySpan<byte> data) | ||||||||||
| { | ||||||||||
| switch (command) | ||||||||||
| { | ||||||||||
| case XboxRiffmasterInput.CommandId: | ||||||||||
| return ParseInput(data); | ||||||||||
|
|
||||||||||
| default: | ||||||||||
| return XboxResult.Success; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private unsafe XboxResult ParseInput(ReadOnlySpan<byte> data) | ||||||||||
| { | ||||||||||
| if (!ParsingUtils.TryRead(data, out XboxRiffmasterInput guitarReport)) | ||||||||||
| return XboxResult.InvalidMessage; | ||||||||||
|
|
||||||||||
| HandleReport(device, guitarReport); | ||||||||||
|
|
||||||||||
| // Send data | ||||||||||
| return SubmitReport(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /// <summary> | ||||||||||
| /// Maps guitar input data to an Xbox 360 controller. | ||||||||||
| /// </summary> | ||||||||||
| internal static void HandleReport(IXbox360Controller device, in XboxRiffmasterInput report) | ||||||||||
| { | ||||||||||
| // Guitar inputs | ||||||||||
| GuitarViGEmMapper.HandleReport(device, report.Base); | ||||||||||
|
|
||||||||||
| // Whammy Bar | ||||||||||
| device.SetAxisValue(Xbox360Axis.LeftThumbY, report.Base.WhammyBar.ScaleToPositiveInt16()); | ||||||||||
|
|
||||||||||
| // Tilt | ||||||||||
| device.SetAxisValue(Xbox360Axis.RightThumbY, (-1 * (int)Math.Round(report.Base.Tilt.ScaleToInt16() * BackendSettings.RiffmasterSensitivity)).ClampToShort()); | ||||||||||
|
|
||||||||||
| // Joystick | ||||||||||
| device.SetButtonState(Xbox360Button.LeftThumb, report.JoystickClick | report.Base.LowerFretsPressed); | ||||||||||
|
|
||||||||||
| // Pickup | ||||||||||
| HandlePickup(report); | ||||||||||
| device.SetSliderValue(Xbox360Slider.LeftTrigger, (byte)(currentPickup * 51 - 25)); | ||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would somewhat prefer if there was a way to use |
||||||||||
| } | ||||||||||
|
|
||||||||||
| private static void HandlePickup(XboxRiffmasterInput report) | ||||||||||
| { | ||||||||||
| bool pickupSetDown = ((XboxGamepadButton)report.Base.Buttons).HasFlag(XboxGamepadButton.LeftStickPress); | ||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use
Suggested change
(Casting the constant to
Suggested change
|
||||||||||
| if (pickupSetDown && !pickupDown) | ||||||||||
| { | ||||||||||
| pickupDown = true; | ||||||||||
| currentPickup++; | ||||||||||
| if (currentPickup > 4) | ||||||||||
| currentPickup = 0; | ||||||||||
| } | ||||||||||
| else if (!pickupSetDown && pickupDown) | ||||||||||
| { | ||||||||||
| pickupDown = false; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -107,6 +107,14 @@ public static short ScaleToInt16(this byte input) | |||||
| { | ||||||
| return (short)(((input ^ 0x80) << 8) | input); | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Scales a byte to a short, starting from 0. | ||||||
| /// </summary> | ||||||
| public static short ScaleToPositiveInt16(this byte input) | ||||||
| { | ||||||
| return (short)(((input / 2) << 8) | input); | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be done equivalently with just bit-shift operations:
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Scales a byte to an unsigned short. | ||||||
|
|
@@ -115,5 +123,17 @@ public static ushort ScaleToUInt16(this byte input) | |||||
| { | ||||||
| return (ushort)((input << 8) | input); | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Clamps an int to a short. | ||||||
| /// </summary> | ||||||
| public static short ClampToShort(this int input) | ||||||
| { | ||||||
| if (input > short.MaxValue) | ||||||
| return short.MaxValue; | ||||||
| else if (input < short.MinValue) | ||||||
| return short.MinValue; | ||||||
| return (short)input; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call as-is is going to cause duplicate inputs with whammy/tilt, as
GuitarViGEmMapper.HandleReportputs whammy on right stick X instead of left thumb Y, and the additional code here does nothing to account for that.I'd prefer if the code in
GuitarViGEmMapper.HandleReportwas duplicated in its entirety into here, and modified to suit shadPS4's mapping requirements.