- Added option to map joy-to-joy
This commit is contained in:
parent
e4c0690306
commit
33ebf58aa3
2 changed files with 131 additions and 97 deletions
|
@ -10,7 +10,7 @@ namespace BetterJoyForCemu {
|
|||
const string PATH = "settings";
|
||||
static Dictionary<string, string> variables = new Dictionary<string, string>();
|
||||
|
||||
const int settingsNum = 9; // currently - ProgressiveScan, StartInTray + special buttons
|
||||
const int settingsNum = 10; // currently - ProgressiveScan, StartInTray + special buttons
|
||||
|
||||
public static string GetDefaultValue(string s) {
|
||||
switch(s) {
|
||||
|
|
|
@ -498,8 +498,13 @@ namespace BetterJoyForCemu {
|
|||
packetCounter++;
|
||||
if (Program.server != null)
|
||||
Program.server.NewReportIncoming(this);
|
||||
}
|
||||
|
||||
if (xin != null)
|
||||
DoThingsWithButtons();
|
||||
SetXInputReportState();
|
||||
|
||||
// no reason to send XInput reports so often
|
||||
if (xin != null) {
|
||||
try {
|
||||
xin.SendReport(report);
|
||||
} catch (Exception e) {
|
||||
|
@ -507,8 +512,6 @@ namespace BetterJoyForCemu {
|
|||
}
|
||||
}
|
||||
|
||||
DoThingsWithButtons();
|
||||
|
||||
if (ts_en == raw_buf[1] && !isSnes) {
|
||||
form.AppendTextBox("Duplicate timestamp enqueued.\r\n");
|
||||
DebugPrint(string.Format("Duplicate timestamp enqueued. TS: {0:X2}", ts_en), DebugType.THREADING);
|
||||
|
@ -521,28 +524,38 @@ namespace BetterJoyForCemu {
|
|||
|
||||
private void Simulate(string s, bool click=true, bool up=false) {
|
||||
if (s.StartsWith("key_")) {
|
||||
WindowsInput.Events.KeyCode key = (WindowsInput.Events.KeyCode)Int32.Parse(s.Substring(4));
|
||||
if (click) {
|
||||
WindowsInput.Simulate.Events().Click((WindowsInput.Events.KeyCode)Int32.Parse(s.Substring(4))).Invoke();
|
||||
WindowsInput.Simulate.Events().Click(key).Invoke();
|
||||
} else {
|
||||
if (up) {
|
||||
WindowsInput.Simulate.Events().Release((WindowsInput.Events.KeyCode)Int32.Parse(s.Substring(4))).Invoke();
|
||||
WindowsInput.Simulate.Events().Release(key).Invoke();
|
||||
} else {
|
||||
WindowsInput.Simulate.Events().Hold((WindowsInput.Events.KeyCode)Int32.Parse(s.Substring(4))).Invoke();
|
||||
WindowsInput.Simulate.Events().Hold(key).Invoke();
|
||||
}
|
||||
}
|
||||
} else if (s.StartsWith("mse_")) {
|
||||
WindowsInput.Events.ButtonCode button = (WindowsInput.Events.ButtonCode)Int32.Parse(s.Substring(4));
|
||||
if (click) {
|
||||
WindowsInput.Simulate.Events().Click((WindowsInput.Events.ButtonCode)Int32.Parse(s.Substring(4))).Invoke();
|
||||
WindowsInput.Simulate.Events().Click(button).Invoke();
|
||||
} else {
|
||||
if (up) {
|
||||
WindowsInput.Simulate.Events().Release((WindowsInput.Events.ButtonCode)Int32.Parse(s.Substring(4))).Invoke();
|
||||
WindowsInput.Simulate.Events().Release(button).Invoke();
|
||||
} else {
|
||||
WindowsInput.Simulate.Events().Hold((WindowsInput.Events.ButtonCode)Int32.Parse(s.Substring(4))).Invoke();
|
||||
WindowsInput.Simulate.Events().Hold(button).Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For Joystick->Joystick inputs
|
||||
private void SimulateContinous(int origin, string s) {
|
||||
if (s.StartsWith("joy_")) {
|
||||
int button = Int32.Parse(s.Substring(4));
|
||||
buttons[button] = buttons[origin];
|
||||
}
|
||||
}
|
||||
|
||||
string extraGyroFeature = ConfigurationManager.AppSettings["GyroToJoyOrMouse"];
|
||||
int GyroMouseSensitivity = Int32.Parse(ConfigurationManager.AppSettings["GyroMouseSensitivity"]);
|
||||
private void DoThingsWithButtons() {
|
||||
|
@ -550,23 +563,41 @@ namespace BetterJoyForCemu {
|
|||
Simulate(Config.Value("capture"));
|
||||
if (buttons_down[(int)Button.HOME])
|
||||
Simulate(Config.Value("home"));
|
||||
if (isLeft && buttons_down[(int)Button.SL])
|
||||
if (buttons[(int)Button.CAPTURE])
|
||||
SimulateContinous((int)Button.CAPTURE, Config.Value("capture"));
|
||||
if (buttons[(int)Button.HOME])
|
||||
SimulateContinous((int)Button.HOME, Config.Value("home"));
|
||||
|
||||
if (isLeft) {
|
||||
if (buttons_down[(int)Button.SL])
|
||||
Simulate(Config.Value("sl_l"), false, false);
|
||||
if (isLeft && buttons_up[(int)Button.SL])
|
||||
if (buttons_up[(int)Button.SL])
|
||||
Simulate(Config.Value("sl_l"), false, true);
|
||||
if (isLeft && buttons_down[(int)Button.SR])
|
||||
if (buttons_down[(int)Button.SR])
|
||||
Simulate(Config.Value("sr_l"), false, false);
|
||||
if (isLeft && buttons_up[(int)Button.SR])
|
||||
if (buttons_up[(int)Button.SR])
|
||||
Simulate(Config.Value("sr_l"), false, true);
|
||||
if (!isLeft && buttons_down[(int)Button.SL])
|
||||
|
||||
if (buttons[(int)Button.SL])
|
||||
SimulateContinous((int)Button.SL, Config.Value("sl_l"));
|
||||
if (buttons[(int)Button.SR])
|
||||
SimulateContinous((int)Button.SR, Config.Value("sr_l"));
|
||||
} else {
|
||||
if (buttons_down[(int)Button.SL])
|
||||
Simulate(Config.Value("sl_r"), false, false);
|
||||
if (!isLeft && buttons_up[(int)Button.SL])
|
||||
if (buttons_up[(int)Button.SL])
|
||||
Simulate(Config.Value("sl_r"), false, true);
|
||||
if (!isLeft && buttons_down[(int)Button.SR])
|
||||
if (buttons_down[(int)Button.SR])
|
||||
Simulate(Config.Value("sr_r"), false, false);
|
||||
if (!isLeft && buttons_up[(int)Button.SR])
|
||||
if (buttons_up[(int)Button.SR])
|
||||
Simulate(Config.Value("sr_r"), false, true);
|
||||
|
||||
if (buttons[(int)Button.SL])
|
||||
SimulateContinous((int)Button.SL, Config.Value("sl_r"));
|
||||
if (buttons[(int)Button.SR])
|
||||
SimulateContinous((int)Button.SR, Config.Value("sr_r"));
|
||||
}
|
||||
|
||||
if (extraGyroFeature == "joy") {
|
||||
// TODO
|
||||
} else if (extraGyroFeature == "mouse" && (isPro || (other == null) || (other != null && (Boolean.Parse(ConfigurationManager.AppSettings["GyroMouseLeftHanded"]) ? isLeft : !isLeft)))) {
|
||||
|
@ -709,7 +740,7 @@ namespace BetterJoyForCemu {
|
|||
buttons[(int)Button.SR] = (report_buf[3 + (isLeft ? 2 : 0)] & 0x10) != 0;
|
||||
buttons[(int)Button.SL] = (report_buf[3 + (isLeft ? 2 : 0)] & 0x20) != 0;
|
||||
|
||||
if (isPro && xin != null) {
|
||||
if (isPro) {
|
||||
buttons[(int)Button.B] = (report_buf[3 + (!isLeft ? 2 : 0)] & (!isLeft ? 0x01 : 0x04)) != 0;
|
||||
buttons[(int)Button.A] = (report_buf[3 + (!isLeft ? 2 : 0)] & (!isLeft ? 0x04 : 0x08)) != 0;
|
||||
buttons[(int)Button.X] = (report_buf[3 + (!isLeft ? 2 : 0)] & (!isLeft ? 0x02 : 0x02)) != 0;
|
||||
|
@ -718,22 +749,6 @@ namespace BetterJoyForCemu {
|
|||
buttons[(int)Button.STICK2] = ((report_buf[4] & (!isLeft ? 0x08 : 0x04)) != 0);
|
||||
buttons[(int)Button.SHOULDER2_1] = (report_buf[3 + (!isLeft ? 2 : 0)] & 0x40) != 0;
|
||||
buttons[(int)Button.SHOULDER2_2] = (report_buf[3 + (!isLeft ? 2 : 0)] & 0x80) != 0;
|
||||
|
||||
report.SetButtonState(Xbox360Buttons.A, buttons[(int)(!swapAB ? Button.B : Button.A)]);
|
||||
report.SetButtonState(Xbox360Buttons.B, buttons[(int)(!swapAB ? Button.A : Button.B)]);
|
||||
report.SetButtonState(Xbox360Buttons.Y, buttons[(int)(!swapXY ? Button.X : Button.Y)]);
|
||||
report.SetButtonState(Xbox360Buttons.X, buttons[(int)(!swapXY ? Button.Y : Button.X)]);
|
||||
report.SetButtonState(Xbox360Buttons.Up, buttons[(int)Button.DPAD_UP]);
|
||||
report.SetButtonState(Xbox360Buttons.Down, buttons[(int)Button.DPAD_DOWN]);
|
||||
report.SetButtonState(Xbox360Buttons.Left, buttons[(int)Button.DPAD_LEFT]);
|
||||
report.SetButtonState(Xbox360Buttons.Right, buttons[(int)Button.DPAD_RIGHT]);
|
||||
report.SetButtonState(Xbox360Buttons.Back, buttons[(int)Button.MINUS]);
|
||||
report.SetButtonState(Xbox360Buttons.Start, buttons[(int)Button.PLUS]);
|
||||
report.SetButtonState(Xbox360Buttons.Guide, buttons[(int)Button.HOME]);
|
||||
report.SetButtonState(Xbox360Buttons.LeftShoulder, buttons[(int)Button.SHOULDER_1]);
|
||||
report.SetButtonState(Xbox360Buttons.RightShoulder, buttons[(int)Button.SHOULDER2_1]);
|
||||
report.SetButtonState(Xbox360Buttons.LeftThumb, buttons[(int)Button.STICK]);
|
||||
report.SetButtonState(Xbox360Buttons.RightThumb, buttons[(int)Button.STICK2]);
|
||||
}
|
||||
|
||||
if (other != null && other != this) {
|
||||
|
@ -756,7 +771,40 @@ namespace BetterJoyForCemu {
|
|||
buttons[(int)Button.MINUS] = other.buttons[(int)Button.MINUS];
|
||||
}
|
||||
|
||||
if (!isPro && xin != null) {
|
||||
lock (buttons_up) {
|
||||
lock (buttons_down) {
|
||||
for (int i = 0; i < buttons.Length; ++i) {
|
||||
buttons_up[i] = (down_[i] & !buttons[i]);
|
||||
buttons_down[i] = (!down_[i] & buttons[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void SetXInputReportState() {
|
||||
if (xin == null)
|
||||
return;
|
||||
|
||||
if (isPro) {
|
||||
report.SetButtonState(Xbox360Buttons.A, buttons[(int)(!swapAB ? Button.B : Button.A)]);
|
||||
report.SetButtonState(Xbox360Buttons.B, buttons[(int)(!swapAB ? Button.A : Button.B)]);
|
||||
report.SetButtonState(Xbox360Buttons.Y, buttons[(int)(!swapXY ? Button.X : Button.Y)]);
|
||||
report.SetButtonState(Xbox360Buttons.X, buttons[(int)(!swapXY ? Button.Y : Button.X)]);
|
||||
report.SetButtonState(Xbox360Buttons.Up, buttons[(int)Button.DPAD_UP]);
|
||||
report.SetButtonState(Xbox360Buttons.Down, buttons[(int)Button.DPAD_DOWN]);
|
||||
report.SetButtonState(Xbox360Buttons.Left, buttons[(int)Button.DPAD_LEFT]);
|
||||
report.SetButtonState(Xbox360Buttons.Right, buttons[(int)Button.DPAD_RIGHT]);
|
||||
report.SetButtonState(Xbox360Buttons.Back, buttons[(int)Button.MINUS]);
|
||||
report.SetButtonState(Xbox360Buttons.Start, buttons[(int)Button.PLUS]);
|
||||
report.SetButtonState(Xbox360Buttons.Guide, buttons[(int)Button.HOME]);
|
||||
report.SetButtonState(Xbox360Buttons.LeftShoulder, buttons[(int)Button.SHOULDER_1]);
|
||||
report.SetButtonState(Xbox360Buttons.RightShoulder, buttons[(int)Button.SHOULDER2_1]);
|
||||
report.SetButtonState(Xbox360Buttons.LeftThumb, buttons[(int)Button.STICK]);
|
||||
report.SetButtonState(Xbox360Buttons.RightThumb, buttons[(int)Button.STICK2]);
|
||||
} else {
|
||||
if (other != null) { // no need for && other != this
|
||||
report.SetButtonState(!swapAB ? Xbox360Buttons.A : Xbox360Buttons.B, buttons[(int)(isLeft ? Button.B : Button.DPAD_DOWN)]);
|
||||
report.SetButtonState(!swapAB ? Xbox360Buttons.B : Xbox360Buttons.A, buttons[(int)(isLeft ? Button.A : Button.DPAD_RIGHT)]);
|
||||
|
@ -792,17 +840,6 @@ namespace BetterJoyForCemu {
|
|||
if (Config.Value("home") != "0")
|
||||
report.SetButtonState(Xbox360Buttons.Guide, false);
|
||||
|
||||
lock (buttons_up) {
|
||||
lock (buttons_down) {
|
||||
for (int i = 0; i < buttons.Length; ++i) {
|
||||
buttons_up[i] = (down_[i] & !buttons[i]);
|
||||
buttons_down[i] = (!down_[i] & buttons[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (xin != null) {
|
||||
if (!isSnes) {
|
||||
if (other != null || isPro) { // no need for && other != this
|
||||
report.SetAxis(Xbox360Axes.LeftThumbX, CastStickValue((other == this && !isLeft) ? stick2[0] : stick[0]));
|
||||
|
@ -818,9 +855,6 @@ namespace BetterJoyForCemu {
|
|||
report.SetAxis(Xbox360Axes.RightTrigger, (short)(buttons[(int)(isLeft ? Button.SHOULDER2_2 : Button.SHOULDER_2)] ? Int16.MaxValue : 0));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get Gyro/Accel data
|
||||
private void ExtractIMUValues(byte[] report_buf, int n = 0) {
|
||||
if (!isSnes) {
|
||||
|
|
Loading…
Add table
Reference in a new issue