589 sprintf_s(msg,
sizeof msg,
"joystick::InitializeDevice Releasing %s", control.c_str());
592 auto releaseDevice = [&](
const char* reason)
594 DWORD releaseExceptionCode = 0;
595 if (GuardedReleaseDevice(&config->
g_pJoystick, &releaseExceptionCode))
598 sprintf_s(msg,
sizeof msg,
599 "joystick::InitializeDevice caught native exception 0x%08lX releasing %s during %s; continuing with the device disabled",
600 releaseExceptionCode, control.c_str(), reason);
603 releaseDevice(
"rebind");
604 DWORD nativeExceptionCode = 0;
611 for (
size_t device = 0; device <
deviceList.size(); device++)
613 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
614 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
615 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
616 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
617 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
618 control ==
"Look Lateral")
623 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
624 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
625 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
626 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
627 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
628 control ==
"Look Vertical")
633 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
634 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
635 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
636 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
637 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
643 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
644 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
645 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
646 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
647 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
653 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-55 Rhino Stick") == 0 ||
654 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-56 Rhino Stick") == 0 ||
655 wcscmp(
deviceList.at(device).tszInstanceName, L
"WingMan Force 3D") == 0 ||
656 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech WingMan Force 3D USB") == 0 ||
657 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Cyborg USB Stick") == 0 ||
658 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D") == 0 ||
659 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D Pro USB") == 0 ||
660 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek ST290 Pro") == 0 ||
661 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.16000M") == 0 ||
662 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas X") == 0 ||
663 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas") == 0 ||
664 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas 4") == 0) &&
665 control ==
"Pitch" && priority > 1)
684 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
685 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
686 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
687 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
688 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
689 control ==
"Pitch" && priority > 9)
695 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-55 Rhino Stick") == 0 ||
696 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-56 Rhino Stick") == 0 ||
697 wcscmp(
deviceList.at(device).tszInstanceName, L
"WingMan Force 3D") == 0 ||
698 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech WingMan Force 3D USB") == 0 ||
699 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Cyborg USB Stick") == 0 ||
700 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D") == 0 ||
701 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D Pro USB") == 0 ||
702 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek ST290 Pro") == 0 ||
703 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.16000M") == 0 ||
704 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas X") == 0 ||
705 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas") == 0 ||
706 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas 4") == 0) &&
707 control ==
"Roll" && priority > 1)
713 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
714 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
715 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
716 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
717 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
718 control ==
"Roll" && priority > 9)
724 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-55 Rhino Stick") == 0 ||
725 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-56 Rhino Stick") == 0 ||
726 wcscmp(
deviceList.at(device).tszInstanceName, L
"WingMan Force 3D") == 0 ||
727 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech WingMan Force 3D USB") == 0 ||
728 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Cyborg USB Stick") == 0 ||
729 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D") == 0 ||
730 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D Pro USB") == 0 ||
731 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek ST290 Pro") == 0 ||
732 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.16000M") == 0 ||
733 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas X") == 0 ||
734 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas") == 0 ||
735 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas 4") == 0) &&
736 control ==
"Yaw" && priority > 1)
742 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-55 Rhino Throttle") == 0 ||
743 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-56 Rhino Throttle") == 0) &&
744 control ==
"Left Thrust" && priority > 1)
750 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"WingMan Force 3D") == 0 ||
751 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech WingMan Force 3D USB") == 0) &&
752 control ==
"Left Thrust" && priority > 2)
758 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Cyborg USB Stick") == 0 ||
759 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D") == 0 ||
760 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D Pro USB") == 0 ||
761 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek ST290 Pro") == 0 ||
762 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas X") == 0 ||
763 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas") == 0 ||
764 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas 4") == 0) &&
765 control ==
"Left Thrust" && priority > 2)
771 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"T.16000M") == 0) &&
772 control ==
"Left Thrust" && priority > 2)
778 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"T.16000M") == 0) &&
779 control ==
"Right Thrust" && priority > 2)
785 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
786 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
787 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
788 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
789 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
790 control ==
"Left Thrust" && priority > 9)
794 config->
split =
true;
797 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-55 Rhino Throttle") == 0 ||
798 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Pro Flight X-56 Rhino Throttle") == 0) &&
799 control ==
"Right Thrust" && priority > 1)
805 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"WingMan Force 3D") == 0 ||
806 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech WingMan Force 3D USB") == 0) &&
807 control ==
"Right Thrust" && priority > 2)
813 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek Cyborg USB Stick") == 0 ||
814 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D") == 0 ||
815 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech Extreme 3D Pro USB") == 0 ||
816 wcscmp(
deviceList.at(device).tszInstanceName, L
"Saitek ST290 Pro") == 0 ||
817 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas X") == 0 ||
818 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas") == 0 ||
819 wcscmp(
deviceList.at(device).tszInstanceName, L
"T.Flight Hotas 4") == 0) &&
820 control ==
"Right Thrust" && priority > 2)
826 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
827 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
828 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
829 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
830 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
831 control ==
"Right Thrust" && priority > 9)
835 config->
split =
true;
838 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
839 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
840 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
841 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
842 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
843 control ==
"Left Toe Brake" && priority > 9)
847 config->
split =
true;
851 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
852 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
853 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
854 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
855 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
856 control ==
"Right Toe Brake" && priority > 9)
860 config->
split =
true;
865#pragma region Steering
867 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (PXN-V3II)") == 0 ||
868 wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech G29 Driving Force Racing Wheel USB") == 0) &&
869 control ==
"Steering" && priority > 1)
878 if (wcscmp(
deviceList.at(device).tszInstanceName, L
"T.16000M") == 0 &&
879 control ==
"Steering" && priority > 2)
885 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
886 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
887 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
888 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
889 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
890 control ==
"Steering" && priority > 9)
899 if (wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (PXN-V3II)") == 0 && control ==
"Gas" && priority > 1)
903 config->
split =
true;
906 if (wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech G29 Driving Force Racing Wheel USB") == 0 && control ==
"Gas" && priority > 1)
910 config->
split =
true;
913 if (wcscmp(
deviceList.at(device).tszInstanceName, L
"T.16000M") == 0 && control ==
"Gas" && priority > 2)
919 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
920 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
921 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
922 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
923 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
924 control ==
"Gas" && priority > 9)
928 config->
split =
true;
931 if (wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (PXN-V3II)") == 0 && control ==
"Brake" && priority > 1)
935 config->
split =
true;
939 if (wcscmp(
deviceList.at(device).tszInstanceName, L
"Logitech G29 Driving Force Racing Wheel USB") == 0 && control ==
"Brake" && priority > 1)
943 config->
split =
true;
947 if ((wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox One For Windows)") == 0 ||
948 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (XBOX 360 For Windows)") == 0 ||
949 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (ZD Game For Windows)") == 0 ||
950 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Gamepad for Xbox 360)") == 0 ||
951 wcscmp(
deviceList.at(device).tszInstanceName, L
"Controller (Xbox 360 Wireless Receiver for Windows)") == 0) &&
952 control ==
"Brake" && priority > 9)
956 config->
split =
true;
982 FormatGuid(config->
guid, guidText,
sizeof guidText);
983 const wchar_t* deviceName = L
"<GUID not present in the enumerated device list>";
986 if (device.guidInstance == config->
guid)
988 deviceName = device.tszInstanceName;
993 sprintf_s(msg,
sizeof msg,
"joystick::InitializeDevice CreateDevice control=%s device=%S GUID=%s",
994 control.c_str(), deviceName, guidText);
999 sprintf_s(msg,
sizeof msg,
1000 "joystick::InitializeDevice cannot initialize control=%s device=%S GUID=%s because DirectInput is null",
1001 control.c_str(), deviceName, guidText);
1007 nativeExceptionCode = 0;
1009 if (nativeExceptionCode != 0)
1011 sprintf_s(msg,
sizeof msg,
1012 "joystick::InitializeDevice caught native exception 0x%08lX in GetDeviceStatus for control=%s device=%S GUID=%s; the device driver may have failed; continuing with the control disabled",
1013 nativeExceptionCode, control.c_str(), deviceName, guidText);
1019 sprintf_s(msg,
sizeof msg,
1020 "joystick::InitializeDevice GetDeviceStatus failed for control=%s device=%S GUID=%s; the device may be disconnected or the GUID may be stale",
1021 control.c_str(), deviceName, guidText);
1027 logger->
Log(
"joystick::InitializeDevice GetDeviceStatus succeeded");
1031 nativeExceptionCode = 0;
1033 if (nativeExceptionCode != 0)
1035 sprintf_s(msg,
sizeof msg,
1036 "joystick::InitializeDevice caught native exception 0x%08lX in CreateDevice for control=%s device=%S GUID=%s; the GUID may be stale or the device driver may have failed; continuing with the control disabled",
1037 nativeExceptionCode, control.c_str(), deviceName, guidText);
1046 sprintf_s(msg,
sizeof msg,
1047 "joystick::InitializeDevice CreateDevice failed for control=%s device=%S GUID=%s; the device may be disconnected or the GUID may be stale",
1048 control.c_str(), deviceName, guidText);
1054 logger->
Log(
"joystick::InitializeDevice CreateDevice succeeded");
1064 logger->
Log(
"joystick::InitializeDevice Calling SetDataFormat...");
1066 nativeExceptionCode = 0;
1067 hr = GuardedSetDataFormat(config->
g_pJoystick, &nativeExceptionCode);
1068 if (nativeExceptionCode != 0)
1070 sprintf_s(msg,
sizeof msg,
1071 "joystick::InitializeDevice caught native exception 0x%08lX in SetDataFormat for control=%s device=%S GUID=%s; continuing with the control disabled",
1072 nativeExceptionCode, control.c_str(), deviceName, guidText);
1074 releaseDevice(
"SetDataFormat native exception cleanup");
1079 sprintf_s(msg,
sizeof msg,
"joystick::InitializeDevice SetDataFormat failed for control=%s device=%S GUID=%s",
1080 control.c_str(), deviceName, guidText);
1082 releaseDevice(
"SetDataFormat failure cleanup");
1085 logger->
Log(
"joystick::InitializeDevice Done with SetDataFormat!");
1090 logger->
Log(
"joystick::InitializeDevice Calling SetCooperativeLevel...");
1092 nativeExceptionCode = 0;
1093 hr = GuardedSetCooperativeLevel(config->
g_pJoystick,
hDlg, &nativeExceptionCode);
1094 if (nativeExceptionCode != 0)
1096 sprintf_s(msg,
sizeof msg,
1097 "joystick::InitializeDevice caught native exception 0x%08lX in SetCooperativeLevel for control=%s device=%S GUID=%s; continuing with the control disabled",
1098 nativeExceptionCode, control.c_str(), deviceName, guidText);
1100 releaseDevice(
"SetCooperativeLevel native exception cleanup");
1105 sprintf_s(msg,
sizeof msg,
"joystick::InitializeDevice SetCooperativeLevel failed for control=%s device=%S GUID=%s",
1106 control.c_str(), deviceName, guidText);
1108 releaseDevice(
"SetCooperativeLevel failure cleanup");
1111 logger->
Log(
"joystick::InitializeDevice Done with SetCooperativeLevel!");
1114 logger->
Log(
"joystick::InitializeDevice Calling EnumObjects for axes...");
1120 nativeExceptionCode = 0;
1122 if (nativeExceptionCode != 0)
1124 sprintf_s(msg,
sizeof msg,
1125 "joystick::InitializeDevice caught native exception 0x%08lX in EnumObjects for control=%s device=%S GUID=%s; continuing with the control disabled",
1126 nativeExceptionCode, control.c_str(), deviceName, guidText);
1128 releaseDevice(
"EnumObjects native exception cleanup");
1133 sprintf_s(msg,
sizeof msg,
"joystick::InitializeDevice EnumObjects failed for control=%s device=%S GUID=%s",
1134 control.c_str(), deviceName, guidText);
1136 releaseDevice(
"EnumObjects failure cleanup");
1139 logger->
Log(
"joystick::InitializeDevice Done with EnumObjects!");