diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..dd6a156 --- /dev/null +++ b/README.txt @@ -0,0 +1,9 @@ +This is the source code! It can NOT be used to play PDAFT! +If you just wanted to play the game, you downloaded the wrong thing. +Do not click the download button next to the git URL, that's for the source code. + +For information on getting and installing the latest release, +please read the wiki at https://notabug.org/nastys/PD-Loader/wiki +If you've already read it, pay more attention and you'll find the right link. + +You should also read the wiki if you have any issues, before asking questions. \ No newline at end of file diff --git a/source-code/data/plugins/genericusbinput.ini b/source-code/data/plugins/genericusbinput.ini new file mode 100644 index 0000000..e58a7b4 --- /dev/null +++ b/source-code/data/plugins/genericusbinput.ini @@ -0,0 +1,10 @@ +#Check you Vendor ID and Product ID in Device Manager or dxdiag tool + +[genericusbinput] + +VID = 046D +PID = C216 + +[customkeymapping] + +GU_BUTTON8 = GU_BUTTON1 + GU_BUTTON2 + GU_BUTTON3 + GU_BUTTON4 diff --git a/source-code/data/plugins/keyconfig.ini b/source-code/data/plugins/keyconfig.ini index 018431d..bcbeaea 100644 --- a/source-code/data/plugins/keyconfig.ini +++ b/source-code/data/plugins/keyconfig.ini @@ -114,3 +114,17 @@ RIGHT_SIDE_SLIDE_RIGHT = O, Ds4_R_Stick_Right, XINPUT_RRIGHT # - Right Joystick # "XINPUT_RLEFT", "XINPUT_RRIGHT", "XINPUT_RUP", "XINPUT_RDOWN", "XINPUT_RSB" + +# --- Generic USB BUTTON NAMES: --- + +# - Standard Buttons (Button number in "Game controller settings", max allowed 13 buttons at the moment) +# "GU_BUTTON1", "GU_BUTTON2", "GU_BUTTON3", "GU_BUTTON4", "GU_BUTTON5", "GU_BUTTON6", "GU_BUTTON7", "GU_BUTTON8", "GU_BUTTON9", "GU_BUTTON10", "GU_BUTTON11", "GU_BUTTON12", "GU_BUTTON13" + +# - D-Pad Directions +# "GU_DPAD_UP", "GU_DPAD_RIGHT", "GU_DPAD_DOWN", "GU_DPAD_LEFT" + +# - Left Joystick +# "GU_L_STICK_UP", "GU_L_STICK_RIGHT", "GU_L_STICK_DOWN", "GU_L_STICK_LEFT" + +# - Right Joystick +# "GU_R_STICK_UP", "GU_R_STICK_RIGHT", "GU_R_STICK_DOWN", "GU_R_STICK_LEFT" diff --git a/source-code/source/plugins/TLAC/FileSystem/ConfigFile.cpp b/source-code/source/plugins/TLAC/FileSystem/ConfigFile.cpp index 379fda2..76d2e5d 100644 --- a/source-code/source/plugins/TLAC/FileSystem/ConfigFile.cpp +++ b/source-code/source/plugins/TLAC/FileSystem/ConfigFile.cpp @@ -47,6 +47,14 @@ namespace TLAC::FileSystem return found ? (float)atof(pair->second.c_str()) : 0.0f; } + std::string ConfigFile::GetStringValue(const std::string& key) + { + auto pair = ConfigMap.find(key); + bool found = pair != ConfigMap.end(); + + return found ? pair->second : ""; + } + void ConfigFile::Parse(std::ifstream &fileStream) { std::string line; diff --git a/source-code/source/plugins/TLAC/FileSystem/ConfigFile.h b/source-code/source/plugins/TLAC/FileSystem/ConfigFile.h index 8f453ea..bf96e27 100644 --- a/source-code/source/plugins/TLAC/FileSystem/ConfigFile.h +++ b/source-code/source/plugins/TLAC/FileSystem/ConfigFile.h @@ -17,6 +17,7 @@ namespace TLAC::FileSystem int GetIntegerValue(const std::string& key); bool GetBooleanValue(const std::string& key); float GetFloatValue(const std::string& key); + std::string GetStringValue(const std::string& key); protected: virtual void Parse(std::ifstream &fileStream) override; diff --git a/source-code/source/plugins/TLAC/Input/Bindings/GuBinding.cpp b/source-code/source/plugins/TLAC/Input/Bindings/GuBinding.cpp new file mode 100644 index 0000000..d88bb29 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/Bindings/GuBinding.cpp @@ -0,0 +1,29 @@ +#include "GuBinding.h" + +namespace TLAC::Input +{ + #define GuInstanceCheckDefault(checkFunc) (GenericUsbInput::InstanceInitialized() ? GenericUsbInput::GetInstance()->checkFunc : false) + + GuBinding::GuBinding(GuButton button) : Button(button) + { + } + + GuBinding::~GuBinding() + { + } + + bool GuBinding::IsDown() + { + return GuInstanceCheckDefault(IsDown(Button)); + } + + bool GuBinding::IsTapped() + { + return GuInstanceCheckDefault(IsTapped(Button)); + } + + bool GuBinding::IsReleased() + { + return GuInstanceCheckDefault(IsReleased(Button)); + } +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/Bindings/GuBinding.h b/source-code/source/plugins/TLAC/Input/Bindings/GuBinding.h new file mode 100644 index 0000000..3fe0429 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/Bindings/GuBinding.h @@ -0,0 +1,19 @@ +#pragma once +#include "IInputBinding.h" +#include "../DirectInput/GenericUsb/GenericUsbInput.h" + +namespace TLAC::Input +{ + class GuBinding : public IInputBinding + { + public: + GuButton Button; + + GuBinding(GuButton button); + ~GuBinding(); + + bool IsDown() override; + bool IsTapped() override; + bool IsReleased() override; + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp new file mode 100644 index 0000000..8a7983e --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp @@ -0,0 +1,205 @@ +#include "GenericUsbInput.h" +#include "../../../Utilities/Math.h" +#include "../../../Utilities/Operations.h" +#include "../../../framework.h" +#include "../../../FileSystem/ConfigFile.h" +#include + +const std::string GU_CONFIG_FILE_NAME = "genericusbinput.ini"; + +namespace TLAC::Input +{ + GenericUsbInput* GenericUsbInput::instance; + + GenericUsbInput::GenericUsbInput() + { + } + + GenericUsbInput::~GenericUsbInput() + { + DI_Dispose(); + } + + bool GenericUsbInput::TryInitializeInstance() + { + if (InstanceInitialized()) + return true; + + if (!DirectInputInitialized()) + return false; + + GenericUsbInput *genericUsbInput = new GenericUsbInput (); + + bool success = genericUsbInput->Initialize(); + instance = success ? genericUsbInput : nullptr; + + if (!success) + delete genericUsbInput; + + return success; + } + + bool GenericUsbInput::Initialize() + { + HRESULT result = NULL; + + FileSystem::ConfigFile configFile(framework::GetModuleDirectory(), GU_CONFIG_FILE_NAME); + configFile.OpenRead(); + + customKeyMapping = configFile.ConfigMap; + + std::string stt = "0x"; + std::string vid = configFile.GetStringValue("VID"); + std::string pid = configFile.GetStringValue("PID"); + + unsigned int gid = std::strtoul((stt + pid + vid).c_str(), 0, 16); + + GUID GUID_GenericUsb = { gid, 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + + result = DI_CreateDevice(GUID_GenericUsb); + + if (!FAILED(result)) + { + if (FAILED(result = DI_SetDataFormat(&c_dfDIJoystick2))) + return false; + + result = DI_Acquire(); + + return true; + } + else + { + return false; + } + } + + bool GenericUsbInput::PollInput() + { + lastState = currentState; + + HRESULT result = NULL; + result = DI_Poll(); + result = DI_GetDeviceState(sizeof(DIJOYSTATE2), ¤tState.DI_JoyState); + + if (result != DI_OK) + return false; + + UpdateInternalGuState(currentState); + + for (int button = 0; button < GU_BUTTON_MAX; button++) + { + bool buttonState = GetButtonState(currentState, (GuButton)button); + currentState.Buttons[button] = buttonState; + + // If custom button is pressed + if (buttonState) + { + // Check whether this button is a custom mapped button + auto customMapping = customKeyMapping.find(buttonNames[button]); + if (customMapping != customKeyMapping.end()) + { + std::vector keys = Utilities::Split(customMapping->second, "+"); + for (std::string key : keys) + { + Utilities::Trim(key); + + auto guButton = KeyConfig::Config::GuMap.find(key.c_str()); + currentState.Buttons[guButton->second] = buttonState; + } + } + } + } + + return true; + } + + void GenericUsbInput::UpdateInternalGuState(GuState &state) + { + if (state.Dpad.IsDown = state.DI_JoyState.rgdwPOV[0] != -1) + { + state.Dpad.Angle = (state.DI_JoyState.rgdwPOV[0] / 100.0f); + + auto direction = Utilities::GetDirection(state.Dpad.Angle); + state.Dpad.Stick = { direction.Y, -direction.X }; + } + else + { + state.Dpad.Angle = 0; + state.Dpad.Stick = GuJoystick(); + } + + state.LeftStick = NormalizeStick(state.DI_JoyState.lX, state.DI_JoyState.lY); + state.RightStick = NormalizeStick(state.DI_JoyState.lZ, state.DI_JoyState.lRz); + + state.LeftTrigger = { NormalizeTrigger(state.DI_JoyState.lRx) }; + state.RightTrigger = { NormalizeTrigger(state.DI_JoyState.lRy) }; + } + + bool GenericUsbInput::IsDown(GuButton button) + { + return currentState.Buttons[button]; + } + + bool GenericUsbInput::IsUp(GuButton button) + { + return !IsDown(button); + } + + bool GenericUsbInput::IsTapped(GuButton button) + { + return IsDown(button) && WasUp(button); + } + + bool GenericUsbInput::IsReleased(GuButton button) + { + return IsUp(button) && WasDown(button); + } + + bool GenericUsbInput::WasDown(GuButton button) + { + return lastState.Buttons[button]; + } + + bool GenericUsbInput::WasUp(GuButton button) + { + return !WasDown(button); + } + + bool GenericUsbInput::MatchesDirection(GuJoystick joystick, GuDirection directionEnum, float threshold) + { + switch (directionEnum) + { + case TLAC::Input::GU_DIR_UP: + return joystick.YAxis <= -threshold; + + case TLAC::Input::GU_DIR_RIGHT: + return joystick.XAxis >= +threshold; + + case TLAC::Input::GU_DIR_DOWN: + return joystick.YAxis >= +threshold; + + case TLAC::Input::GU_DIR_LEFT: + return joystick.XAxis <= -threshold; + + default: + return false; + } + } + + bool GenericUsbInput::GetButtonState(GuState &state, GuButton button) + { + if (button >= GU_BUTTON1 && button <= GU_BUTTON13) + return state.DI_JoyState.rgbButtons[button]; + + if (button >= GU_DPAD_UP && button <= GU_DPAD_LEFT) + return state.Dpad.IsDown ? MatchesDirection(state.Dpad.Stick, (GuDirection)(button - GU_DPAD_UP), dpadThreshold) : false; + + if (button >= GU_L_STICK_UP && button <= GU_L_STICK_LEFT) + return MatchesDirection(state.LeftStick, (GuDirection)(button - GU_L_STICK_UP), joystickThreshold); + + if (button >= GU_R_STICK_UP && button <= GU_R_STICK_LEFT) + return MatchesDirection(state.RightStick, (GuDirection)(button - GU_R_STICK_UP), joystickThreshold); + + return false; + } +} diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h new file mode 100644 index 0000000..1178342 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h @@ -0,0 +1,85 @@ +#pragma once +#include "../Controller.h" +#include "../../IInputDevice.h" +#include "../../../Input/KeyConfig/Config.h" +#include "GuState.h" +#include + +namespace TLAC::Input +{ + class GenericUsbInput : public Controller, public IInputDevice + { + public: + GenericUsbInput(); + ~GenericUsbInput(); + + static bool TryInitializeInstance(); + + bool Initialize(); + bool PollInput() override; + + bool IsDown(GuButton button); + bool IsUp(GuButton button); + bool IsTapped(GuButton button); + bool IsReleased(GuButton button); + bool WasDown(GuButton button); + bool WasUp(GuButton button); + + inline GuJoystick GetLeftStick() { return currentState.LeftStick; }; + inline GuJoystick GetRightStick() { return currentState.RightStick; }; + inline GuJoystick GetDpad() { return currentState.Dpad.Stick; }; + + static inline bool InstanceInitialized() { return instance != nullptr; }; + static inline GenericUsbInput* GetInstance() { return instance; }; + static inline void DeleteInstance() { delete instance; instance = nullptr; }; + + private: + static GenericUsbInput* instance; + + GuState lastState; + GuState currentState; + + std::unordered_map customKeyMapping; + + std::vector buttonNames = { "GU_BUTTON1", + "GU_BUTTON2", + "GU_BUTTON3", + "GU_BUTTON4", + "GU_BUTTON5", + "GU_BUTTON6", + "GU_BUTTON7", + "GU_BUTTON8", + "GU_BUTTON9", + "GU_BUTTON10", + "GU_BUTTON11", + "GU_BUTTON12", + "GU_BUTTON13", + "GU_DPAD_UP", + "GU_DPAD_RIGHT", + "GU_DPAD_DOWN", + "GU_DPAD_LEFT", + "GU_L_STICK_UP", + "GU_L_STICK_RIGHT", + "GU_L_STICK_DOWN", + "GU_L_STICK_LEFT", + "GU_R_STICK_UP", + "GU_R_STICK_RIGHT", + "GU_R_STICK_DOWN", + "GU_R_STICK_LEFT", + "GU_BUTTON_MAX" + }; + + const float triggerThreshold = 0.5f; + const float joystickThreshold = 0.5f; + const float dpadThreshold = 0.5f; + + inline float NormalizeTrigger(long value) { return (float)value / USHRT_MAX; }; + inline float NormalizeStick(long value) { return (float)value / USHRT_MAX * 2.0f - 1.0f; }; + inline GuJoystick NormalizeStick(long x, long y) { return GuJoystick(NormalizeStick(x), NormalizeStick(y)); }; + + void UpdateInternalGuState(GuState &state); + + bool MatchesDirection(GuJoystick joystick, GuDirection directionEnum, float threshold); + bool GetButtonState(GuState &state, GuButton button); + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuButton.h b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuButton.h new file mode 100644 index 0000000..1df2e2a --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuButton.h @@ -0,0 +1,52 @@ +#pragma once + +namespace TLAC::Input +{ + enum GuDirection + { + GU_DIR_UP, + GU_DIR_RIGHT, + GU_DIR_DOWN, + GU_DIR_LEFT + }; + + enum GuButton : int + { + GU_BUTTON1 = 0, + GU_BUTTON2 = 1, + GU_BUTTON3 = 2, + GU_BUTTON4 = 3, + + GU_BUTTON5 = 4, + GU_BUTTON6 = 5, + + GU_BUTTON7 = 6, + GU_BUTTON8 = 7, + + GU_BUTTON9 = 8, + GU_BUTTON10 = 9, + + GU_BUTTON11 = 10, + GU_BUTTON12 = 11, + + GU_BUTTON13 = 12, + + + GU_DPAD_UP = 14, + GU_DPAD_RIGHT = 15, + GU_DPAD_DOWN = 16, + GU_DPAD_LEFT = 17, + + GU_L_STICK_UP = 18, + GU_L_STICK_RIGHT = 19, + GU_L_STICK_DOWN = 20, + GU_L_STICK_LEFT = 21, + + GU_R_STICK_UP = 22, + GU_R_STICK_RIGHT = 23, + GU_R_STICK_DOWN = 24, + GU_R_STICK_LEFT = 25, + + GU_BUTTON_MAX = 26, + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.cpp b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.cpp new file mode 100644 index 0000000..cc60409 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.cpp @@ -0,0 +1,14 @@ +#include "GuState.h" + +namespace TLAC::Input +{ + GuJoystick::GuJoystick() : XAxis(0.0f), YAxis(0.0f) + { + return; + }; + + GuJoystick::GuJoystick(float xAxis, float yAxis) : XAxis(xAxis), YAxis(yAxis) + { + return; + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.h b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.h new file mode 100644 index 0000000..9060e8d --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.h @@ -0,0 +1,39 @@ +#pragma once +#include "../DirectInput.h" +#include "GuButton.h" + +namespace TLAC::Input +{ + struct GuJoystick + { + FLOAT XAxis, YAxis; + + GuJoystick(); + GuJoystick(float xAxis, float yAxis); + }; + + struct GuDpad + { + BOOL IsDown; + FLOAT Angle; + GuJoystick Stick; + }; + + struct GuTrigger + { + FLOAT Axis; + }; + + struct GuState + { + DIJOYSTATE2 DI_JoyState; + + BYTE Buttons[GU_BUTTON_MAX]; + + GuDpad Dpad; + GuJoystick LeftStick; + GuJoystick RightStick; + GuTrigger LeftTrigger; + GuTrigger RightTrigger; + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/KeyConfig/Config.cpp b/source-code/source/plugins/TLAC/Input/KeyConfig/Config.cpp index a045fe2..0009a6d 100644 --- a/source-code/source/plugins/TLAC/Input/KeyConfig/Config.cpp +++ b/source-code/source/plugins/TLAC/Input/KeyConfig/Config.cpp @@ -2,6 +2,7 @@ #include "windows.h" #include "../Bindings/KeyboardBinding.h" #include "../Bindings/Ds4Binding.h" +#include "../Bindings/GuBinding.h" #include "../../Utilities/Operations.h" #include "../Bindings/XinputBinding.h" #include "../../Constants.h" @@ -218,6 +219,43 @@ namespace TLAC::Input::KeyConfig { "Ds4_R_Stick_Left", DS4_R_STICK_LEFT }, }; + GuButtonMap Config::GuMap = + { + // Face Buttons + { "GU_BUTTON1", GU_BUTTON1 }, + { "GU_BUTTON2", GU_BUTTON2 }, + { "GU_BUTTON3", GU_BUTTON3 }, + { "GU_BUTTON4", GU_BUTTON4 }, + { "GU_BUTTON5", GU_BUTTON5 }, + { "GU_BUTTON6", GU_BUTTON6 }, + { "GU_BUTTON7", GU_BUTTON7 }, + { "GU_BUTTON8", GU_BUTTON8 }, + { "GU_BUTTON9", GU_BUTTON9 }, + { "GU_BUTTON10", GU_BUTTON10 }, + { "GU_BUTTON11", GU_BUTTON11 }, + { "GU_BUTTON12", GU_BUTTON12 }, + { "GU_BUTTON13", GU_BUTTON13 }, + + // D-Pad Directions + { "GU_DPAD_UP", GU_DPAD_UP }, + { "GU_DPAD_RIGHT", GU_DPAD_RIGHT }, + { "GU_DPAD_DOWN", GU_DPAD_DOWN }, + { "GU_DPAD_LEFT", GU_DPAD_LEFT }, + + // Left Joystick + { "GU_L_STICK_UP", GU_L_STICK_UP }, + { "GU_L_STICK_RIGHT", GU_L_STICK_RIGHT }, + { "GU_L_STICK_DOWN", GU_L_STICK_DOWN }, + { "GU_L_STICK_LEFT", GU_L_STICK_LEFT }, + + // Right Joystick + { "GU_R_STICK_UP", GU_R_STICK_UP }, + { "GU_R_STICK_RIGHT", GU_R_STICK_RIGHT }, + { "GU_R_STICK_DOWN", GU_R_STICK_DOWN }, + { "GU_R_STICK_LEFT", GU_R_STICK_LEFT }, + + }; + void Config::BindConfigKeys(std::unordered_map &configMap, const char *configKeyName, Binding &bindObj, std::vector defaultKeys) { std::vector keys; @@ -271,7 +309,16 @@ namespace TLAC::Input::KeyConfig } else { - printf("[TLAC] Config::BindConfigKeys(): Unable to parse key: '%s'\n", key.c_str()); + auto guButton = Config::GuMap.find(key.c_str()); + + if (guButton != Config::GuMap.end()) + { + bindObj.AddBinding(new GuBinding(guButton->second)); + } + else + { + printf("[TLAC] Config::BindConfigKeys(): Unable to parse key: '%s'\n", key.c_str()); + } } } } diff --git a/source-code/source/plugins/TLAC/Input/KeyConfig/Config.h b/source-code/source/plugins/TLAC/Input/KeyConfig/Config.h index 194cd13..2a19842 100644 --- a/source-code/source/plugins/TLAC/Input/KeyConfig/Config.h +++ b/source-code/source/plugins/TLAC/Input/KeyConfig/Config.h @@ -5,11 +5,13 @@ #include "KeyStringHash.h" #include "../Bindings/Binding.h" #include "../DirectInput/Ds4/Ds4Button.h" +#include "../DirectInput/GenericUsb/GuButton.h" namespace TLAC::Input::KeyConfig { typedef std::unordered_map KeycodeMap; typedef std::unordered_map Ds4ButtonMap; + typedef std::unordered_map GuButtonMap; class Config { @@ -17,6 +19,7 @@ namespace TLAC::Input::KeyConfig static KeycodeMap Keymap; static Ds4ButtonMap Ds4Map; static KeycodeMap XinputMap; + static GuButtonMap GuMap; static void BindConfigKeys(std::unordered_map &configMap, const char *configKeyName, Binding &bindObj, std::vector defaultKeys); }; diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj b/source-code/source/plugins/TLAC/TLAC.vcxproj index 11ad581..53edba2 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj @@ -140,6 +140,7 @@ + @@ -151,6 +152,9 @@ + + + @@ -194,6 +198,7 @@ + @@ -203,6 +208,8 @@ + + diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters index 79143c4..41ff9d0 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters @@ -201,6 +201,18 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + @@ -341,5 +353,14 @@ Source Files + + Source Files + + + Source Files + + + Source Files + \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/dllmain.cpp b/source-code/source/plugins/TLAC/dllmain.cpp index 8fcf92f..8b60ed5 100644 --- a/source-code/source/plugins/TLAC/dllmain.cpp +++ b/source-code/source/plugins/TLAC/dllmain.cpp @@ -11,6 +11,7 @@ #include "Input/Keyboard/Keyboard.h" #include "Input/DirectInput/DirectInput.h" #include "Input/DirectInput/Ds4/DualShock4.h" +#include "Input/DirectInput/GenericUsb/GenericUsbInput.h" #include "Components/ComponentsManager.h" #include #include @@ -74,6 +75,12 @@ namespace TLAC if (Input::DualShock4::TryInitializeInstance()) printf("[TLAC] UpdateTick(): DualShock4 connected and initialized\n"); } + + if (!Input::GenericUsbInput::InstanceInitialized()) + { + if (Input::GenericUsbInput::TryInitializeInstance()) + printf("[TLAC] UpdateTick(): GenericUsbInput connected and initialized\n"); + } } ComponentsManager.Update(); @@ -96,6 +103,15 @@ namespace TLAC } } + if (Input::GenericUsbInput::GetInstance() != nullptr) + { + if (!Input::GenericUsbInput::GetInstance()->PollInput()) + { + Input::GenericUsbInput::DeleteInstance(); + printf("[TLAC] UpdateTick(): GenericUsbInput connection lost\n"); + } + } + ComponentsManager.UpdateInput(); } @@ -115,6 +131,15 @@ namespace TLAC printf("[TLAC] UpdateTick(): DualShock4 connection lost\n"); } } + + if (Input::GenericUsbInput::GetInstance() != nullptr) + { + if (!Input::GenericUsbInput::GetInstance()->PollInput()) + { + Input::GenericUsbInput::DeleteInstance(); + printf("[TLAC] UpdateTick(): GenericUsbInput connection lost\n"); + } + } } if (HasWindowFocus && !HadWindowFocus) @@ -232,6 +257,7 @@ namespace TLAC delete Input::Keyboard::GetInstance(); delete Input::Mouse::GetInstance(); delete Input::DualShock4::GetInstance(); + delete Input::GenericUsbInput::GetInstance(); Input::DisposeDirectInput();