From 6f884b87b873c431c0d7ccf67092d4800cc6507e Mon Sep 17 00:00:00 2001 From: chihirobelmo <32677587+chihirobelmo@users.noreply.github.com> Date: Fri, 1 Jul 2022 23:02:23 +0900 Subject: [PATCH] Develop (#68) * now supports both 4.35 DX32 and 4.36 DX128 key mapping * DRY but I don't know if it is a good way * added comment * fixed AB/IDLE detent bytes to little endian * Fixed AB/IDLE detent when throttle axis is inverted. * Fixed throttle invert doesn't apply AB/IDLE position properly * formatting * invelid value check and format * Removed resorting device order by assigned callback numbers as it may causing some issues. Also no more needed as 4.36 supports DX128 * 16 devices. --- .../Input/CommonConstants.cs | 3 ++ .../Input/JoyAssgn.cs | 11 +++---- .../Override/OverrideSetting.cs | 29 ++++++++++-------- .../Override/OverrideSettingFor434.cs | 22 ++++++++------ .../Override/OverrideSettingFor434U1.cs | 4 +-- .../Override/OverrideSettingFor436.cs | 5 ++++ .../Windows/AxisAssignWindow.xaml.cs | 30 +++++++++++-------- .../Windows/MainWindow.xaml.cs | 1 - .../Windows/MainWindowKeyMapping.cs | 2 -- 9 files changed, 63 insertions(+), 44 deletions(-) diff --git a/Falcon BMS Alternative Launcher/Input/CommonConstants.cs b/Falcon BMS Alternative Launcher/Input/CommonConstants.cs index d967c8d..2d92e07 100644 --- a/Falcon BMS Alternative Launcher/Input/CommonConstants.cs +++ b/Falcon BMS Alternative Launcher/Input/CommonConstants.cs @@ -29,5 +29,8 @@ public static class CommonConstants public static readonly int AXISMIN = 0; public static readonly int AXISMAX = 65536; + + public static readonly int BINAXISMIN = 0; + public static readonly int BINAXISMAX = 15000; } } diff --git a/Falcon BMS Alternative Launcher/Input/JoyAssgn.cs b/Falcon BMS Alternative Launcher/Input/JoyAssgn.cs index 9aac27d..34a40d2 100644 --- a/Falcon BMS Alternative Launcher/Input/JoyAssgn.cs +++ b/Falcon BMS Alternative Launcher/Input/JoyAssgn.cs @@ -196,8 +196,9 @@ public string GetDeviceSortingLine() /// /// Get whole DX button assignment line to write a key file. + /// DXnumber: total DXnumber per device BMS can handle. /// - public string GetKeyLineDX(int joynum, int numOfDevices) + public string GetKeyLineDX(int joynum, int numOfDevices, int DXnumber) { string assign = ""; assign += "\n#======== " + GetProductName() + " ========\n"; @@ -212,7 +213,7 @@ public string GetKeyLineDX(int joynum, int numOfDevices) if (ii != 0) continue; assign += dx[i].assign[ii].GetCallback(); - assign += " " + (joynum * CommonConstants.DX128 + i); + assign += " " + (joynum * DXnumber + i); assign += " " + (int)Invoke.Default; assign += " " + "-2"; assign += " " + "0"; @@ -220,7 +221,7 @@ public string GetKeyLineDX(int joynum, int numOfDevices) assign += " " + dx[i].assign[ii].GetSoundID(); assign += "\n"; assign += dx[i].assign[ii].GetCallback(); - assign += " " + (numOfDevices * CommonConstants.DX128 + joynum * CommonConstants.DX128 + i); + assign += " " + (numOfDevices * DXnumber + joynum * DXnumber + i); assign += " " + (int)Invoke.Default; assign += " " + "-2"; assign += " " + "0"; @@ -233,9 +234,9 @@ public string GetKeyLineDX(int joynum, int numOfDevices) assign += dx[i].assign[ii].GetCallback(); if (ii == CommonConstants.DX_PRESS | ii == CommonConstants.DX_RELEASE) - assign += " " + (joynum * CommonConstants.DX128 + i); + assign += " " + (joynum * DXnumber + i); if (ii == CommonConstants.DX_PRESS_SHIFT | ii == CommonConstants.DX_RELEASE_SHIFT) - assign += " " + (numOfDevices * CommonConstants.DX128 + joynum * CommonConstants.DX128 + i); + assign += " " + (numOfDevices * DXnumber + joynum * DXnumber + i); assign += " " + (int)dx[i].assign[ii].GetInvoke(); assign += " " + "-2"; diff --git a/Falcon BMS Alternative Launcher/Override/OverrideSetting.cs b/Falcon BMS Alternative Launcher/Override/OverrideSetting.cs index d7907a4..d21292a 100644 --- a/Falcon BMS Alternative Launcher/Override/OverrideSetting.cs +++ b/Falcon BMS Alternative Launcher/Override/OverrideSetting.cs @@ -41,8 +41,6 @@ public void Execute(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile k if (!Directory.Exists(appReg.GetInstallDir() + "/User/Config/Backup/")) Directory.CreateDirectory(appReg.GetInstallDir() + "/User/Config/Backup/"); - MainWindow.deviceControl.SortDevice(); - SaveAxisMapping(inGameAxis, deviceControl); SaveJoystickCal(inGameAxis, deviceControl); SaveDeviceSorting(deviceControl); @@ -202,10 +200,7 @@ protected void SaveDeviceSorting(DeviceControl deviceControl) ds.Close(); } - /// - /// As the name implies... - /// - protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile) + protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile, int DXnumber) { string filename = appReg.GetInstallDir() + "/User/Config/" + appReg.getAutoKeyFileName(); @@ -218,7 +213,7 @@ protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl device sw.Write(keyFile.keyAssign[i].GetKeyLine()); for (int i = 0; i < deviceControl.joyAssign.Length; i++) { - sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length)); + sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length, DXnumber)); // PRIMARY DEVICE POV if (((InGameAxAssgn)inGameAxis["Roll"]).GetDeviceNumber() == i) sw.Write(deviceControl.joyAssign[i].GetKeyLinePOV()); @@ -226,6 +221,11 @@ protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl device sw.Close(); } + protected virtual void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile) + { + SaveKeyMapping(inGameAxis, deviceControl, keyFile, CommonConstants.DX32); + } + /// /// Overwrite callsign.pop file. /// @@ -443,17 +443,20 @@ protected virtual void SaveJoystickCal(Hashtable inGameAxis, DeviceControl devic double iAB = deviceControl.joyAssign[((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber()].detentPosition.GetAB(); double iIdle = deviceControl.joyAssign[((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber()].detentPosition.GetIDLE(); - const double MAXIN = 65536; - const double MAXOUT = 14848; + iAB = iAB * CommonConstants.BINAXISMAX / CommonConstants.AXISMAX; + iIdle = iIdle * CommonConstants.BINAXISMAX / CommonConstants.AXISMAX; - iAB = -iAB * (MAXOUT / MAXIN) + MAXOUT; - iIdle = -iIdle * (MAXOUT / MAXIN) + MAXOUT; + if (((InGameAxAssgn)inGameAxis[nme.ToString()]).GetInvert() == false) + { + iAB = CommonConstants.BINAXISMAX - iAB; + iIdle = CommonConstants.BINAXISMAX - iIdle; + } byte[] ab = BitConverter.GetBytes((int)iAB).Reverse().ToArray(); byte[] idle = BitConverter.GetBytes((int)iIdle).Reverse().ToArray(); - bs[1] = ab[1]; - bs[5] = idle[1]; + bs[1] = ab[2]; + bs[5] = idle[2]; } } } diff --git a/Falcon BMS Alternative Launcher/Override/OverrideSettingFor434.cs b/Falcon BMS Alternative Launcher/Override/OverrideSettingFor434.cs index 75e3d24..8c891a3 100644 --- a/Falcon BMS Alternative Launcher/Override/OverrideSettingFor434.cs +++ b/Falcon BMS Alternative Launcher/Override/OverrideSettingFor434.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.IO; +using System.Linq; using System.Text; using System.Xml.Serialization; @@ -58,20 +59,23 @@ protected override void SaveJoystickCal(Hashtable inGameAxis, DeviceControl devi { if (((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber() >= 0) { - double iAB = deviceControl.joyAssign[((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber()].detentPosition.GetAB(); + double iAB = deviceControl.joyAssign[((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber()].detentPosition.GetAB(); double iIdle = deviceControl.joyAssign[((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber()].detentPosition.GetIDLE(); - const double MAXIN = 65536; - const double MAXOUT = 14848; + iAB = iAB * CommonConstants.BINAXISMAX / CommonConstants.AXISMAX; + iIdle = iIdle * CommonConstants.BINAXISMAX / CommonConstants.AXISMAX; - iAB = -iAB * (MAXOUT / MAXIN) + MAXOUT; - iIdle = -iIdle * (MAXOUT / MAXIN) + MAXOUT; + if (((InGameAxAssgn)inGameAxis[nme.ToString()]).GetInvert() == false) + { + iAB = CommonConstants.BINAXISMAX - iAB; + iIdle = CommonConstants.BINAXISMAX - iIdle; + } - byte[] ab = BitConverter.GetBytes((int)iAB); - byte[] idle = BitConverter.GetBytes((int)iIdle); + byte[] ab = BitConverter.GetBytes((int)iAB).Reverse().ToArray(); + byte[] idle = BitConverter.GetBytes((int)iIdle).Reverse().ToArray(); - bs[1] = ab[1]; - bs[5] = idle[1]; + bs[1] = ab[2]; + bs[5] = idle[2]; } } } diff --git a/Falcon BMS Alternative Launcher/Override/OverrideSettingFor434U1.cs b/Falcon BMS Alternative Launcher/Override/OverrideSettingFor434U1.cs index 2fa5544..7f07e36 100644 --- a/Falcon BMS Alternative Launcher/Override/OverrideSettingFor434U1.cs +++ b/Falcon BMS Alternative Launcher/Override/OverrideSettingFor434U1.cs @@ -59,7 +59,7 @@ protected override void SaveConfigfile(Hashtable inGameAxis, DeviceControl devic cfg.Close(); } - protected override void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile) + protected override void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile, int DXnumber) { string filename = appReg.GetInstallDir() + "/User/Config/" + appReg.getAutoKeyFileName(); @@ -72,7 +72,7 @@ protected override void SaveKeyMapping(Hashtable inGameAxis, DeviceControl devic sw.Write(keyFile.keyAssign[i].GetKeyLine()); for (int i = 0; i < deviceControl.joyAssign.Length; i++) { - sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length)); + sw.Write(deviceControl.joyAssign[i].GetKeyLineDX(i, deviceControl.joyAssign.Length, DXnumber)); // PRIMARY DEVICE POV if (((InGameAxAssgn)inGameAxis["Roll"]).GetDeviceNumber() == i && ((InGameAxAssgn)inGameAxis["Roll"]).GetDeviceNumber() == ((InGameAxAssgn)inGameAxis["Throttle"]).GetDeviceNumber()) { diff --git a/Falcon BMS Alternative Launcher/Override/OverrideSettingFor436.cs b/Falcon BMS Alternative Launcher/Override/OverrideSettingFor436.cs index 85363f4..b540c36 100644 --- a/Falcon BMS Alternative Launcher/Override/OverrideSettingFor436.cs +++ b/Falcon BMS Alternative Launcher/Override/OverrideSettingFor436.cs @@ -60,5 +60,10 @@ protected override void SaveConfigfile(Hashtable inGameAxis, DeviceControl devic cfg.Write("set g_nPOV2ID 0 // SETUP OVERRIDE\r\n"); cfg.Close(); } + + protected override void SaveKeyMapping(Hashtable inGameAxis, DeviceControl deviceControl, KeyFile keyFile) + { + SaveKeyMapping(inGameAxis, deviceControl, keyFile, CommonConstants.DX128); + } } } diff --git a/Falcon BMS Alternative Launcher/Windows/AxisAssignWindow.xaml.cs b/Falcon BMS Alternative Launcher/Windows/AxisAssignWindow.xaml.cs index 9c2749d..6ab7f02 100644 --- a/Falcon BMS Alternative Launcher/Windows/AxisAssignWindow.xaml.cs +++ b/Falcon BMS Alternative Launcher/Windows/AxisAssignWindow.xaml.cs @@ -518,25 +518,31 @@ private void SetAB_Click(object sender, RoutedEventArgs e) { if (status != Status.ShowAxisStatus) return; - int ABposition; - ABposition = CommonConstants.AXISMAX - MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp); - if (MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp) > CommonConstants.AXISMAX) - ABposition = CommonConstants.AXISMAX; - AB = ABposition; - if (AB > CommonConstants.AXISMAX - CommonConstants.AXISMAX / 128) + + if (Invert.IsChecked == true) + AB = CommonConstants.AXISMIN + MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp); + else + AB = CommonConstants.AXISMAX - MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp); + + if (AB > CommonConstants.AXISMAX) AB = CommonConstants.AXISMAX; + if (AB < CommonConstants.AXISMIN) + AB = CommonConstants.AXISMIN; } private void SetIDLE_Click(object sender, RoutedEventArgs e) { if (status != Status.ShowAxisStatus) return; - int IDLEposition; - IDLEposition = CommonConstants.AXISMAX - MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp); - if (MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp) < 0) - IDLEposition = CommonConstants.AXISMIN; - IDLE = IDLEposition; - if (IDLE < CommonConstants.AXISMAX / 128) + + if (Invert.IsChecked == true) + IDLE = CommonConstants.AXISMIN + MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp); + else + IDLE = CommonConstants.AXISMAX - MainWindow.deviceControl.joyAssign[devNumTmp].JoyAxisState(phyAxNumTmp); + + if (IDLE > CommonConstants.AXISMAX) + IDLE = CommonConstants.AXISMAX; + if (IDLE < CommonConstants.AXISMIN) IDLE = CommonConstants.AXISMIN; } diff --git a/Falcon BMS Alternative Launcher/Windows/MainWindow.xaml.cs b/Falcon BMS Alternative Launcher/Windows/MainWindow.xaml.cs index 34a4de4..b7e8909 100644 --- a/Falcon BMS Alternative Launcher/Windows/MainWindow.xaml.cs +++ b/Falcon BMS Alternative Launcher/Windows/MainWindow.xaml.cs @@ -236,7 +236,6 @@ public void ReloadDevices() { // Get Devices deviceControl = new DeviceControl(appReg); - deviceControl.SortDevice(); neutralButtons = new NeutralButtons[deviceControl.joyAssign.Length]; diff --git a/Falcon BMS Alternative Launcher/Windows/MainWindowKeyMapping.cs b/Falcon BMS Alternative Launcher/Windows/MainWindowKeyMapping.cs index f9f9973..eee938d 100644 --- a/Falcon BMS Alternative Launcher/Windows/MainWindowKeyMapping.cs +++ b/Falcon BMS Alternative Launcher/Windows/MainWindowKeyMapping.cs @@ -105,8 +105,6 @@ private void DataGrid_MouseButtonDoubleClick(object sender, MouseButtonEventArgs return; KeyMappingWindow.ShowKeyMappingWindow(this, selectedItem, keyFile, deviceControl, sender); - - deviceControl.SortDevice(); ResortDevices(); KeyMappingGrid.Items.Refresh();