From 4c836916b1b9962efb26bd23b146256e19eaa22d Mon Sep 17 00:00:00 2001 From: Delta <46466697+DeltaGW2@users.noreply.github.com> Date: Mon, 29 Jul 2024 22:19:50 +0200 Subject: [PATCH] input bind housekeeping --- Nexus.vcxproj | 4 +- Nexus.vcxproj.filters | 11 ++- src/GUI/Widgets/Debug/CDebugWindow.cpp | 2 +- src/GUI/Widgets/Options/COptionsWindow.cpp | 4 +- src/Inputs/GameBinds/GameBindsHandler.cpp | 72 +++++++++---------- src/Inputs/GameBinds/GameBindsHandler.h | 6 +- src/Inputs/InputBinds/ActiveInputBind.h | 21 ------ src/Inputs/InputBinds/EInputBindHandlerType.h | 22 ++++++ src/Inputs/InputBinds/EInputBindType.h | 22 ++++++ src/Inputs/InputBinds/FuncDefs.h | 4 +- src/Inputs/InputBinds/InputBind.cpp | 29 +++++--- src/Inputs/InputBinds/InputBind.h | 47 ++++++++++-- src/Inputs/InputBinds/InputBindHandler.cpp | 40 ++++++----- src/Inputs/InputBinds/InputBindHandler.h | 23 +++--- src/Inputs/InputBinds/ManagedInputBind.h | 25 +++++++ src/Main.cpp | 2 +- 16 files changed, 225 insertions(+), 109 deletions(-) delete mode 100644 src/Inputs/InputBinds/ActiveInputBind.h create mode 100644 src/Inputs/InputBinds/EInputBindHandlerType.h create mode 100644 src/Inputs/InputBinds/EInputBindType.h create mode 100644 src/Inputs/InputBinds/ManagedInputBind.h diff --git a/Nexus.vcxproj b/Nexus.vcxproj index c53e6f3..a069c19 100644 --- a/Nexus.vcxproj +++ b/Nexus.vcxproj @@ -88,6 +88,8 @@ + + @@ -139,7 +141,7 @@ - + diff --git a/Nexus.vcxproj.filters b/Nexus.vcxproj.filters index 2f10dfc..90a28f7 100644 --- a/Nexus.vcxproj.filters +++ b/Nexus.vcxproj.filters @@ -160,6 +160,9 @@ {f0552fcd-0842-4914-bd35-54f18d11b0cd} + + {5f7a3796-ab71-4979-ace3-8063d007c8b8} + @@ -533,7 +536,7 @@ _GLOBAL - + Inputs\InputBinds @@ -1142,6 +1145,12 @@ GUI\Widgets\QuickAccess + + Inputs\InputBinds\Enums + + + Inputs\InputBinds\Enums + diff --git a/src/GUI/Widgets/Debug/CDebugWindow.cpp b/src/GUI/Widgets/Debug/CDebugWindow.cpp index 8912dd5..96f0eec 100644 --- a/src/GUI/Widgets/Debug/CDebugWindow.cpp +++ b/src/GUI/Widgets/Debug/CDebugWindow.cpp @@ -125,7 +125,7 @@ namespace GUI { ImGui::BeginChild("##InputBindsTabScroll", ImVec2(ImGui::GetWindowContentRegionWidth(), 0.0f)); - std::map InputBindRegistry = InputBindApi->GetRegistry(); + std::map InputBindRegistry = InputBindApi->GetRegistry(); for (auto& [identifier, inputBind] : InputBindRegistry) { diff --git a/src/GUI/Widgets/Options/COptionsWindow.cpp b/src/GUI/Widgets/Options/COptionsWindow.cpp index 7788856..b792e88 100644 --- a/src/GUI/Widgets/Options/COptionsWindow.cpp +++ b/src/GUI/Widgets/Options/COptionsWindow.cpp @@ -40,7 +40,7 @@ namespace GUI struct InputBindPacked { std::string KeysText; - ActiveInputBind Bind; + ManagedInputBind Bind; }; struct KBCat @@ -306,7 +306,7 @@ namespace GUI InputBindCategoryMap.clear(); /* copy of all InputBinds */ - std::map InputBindRegistry = InputBindApi->GetRegistry(); + std::map InputBindRegistry = InputBindApi->GetRegistry(); /* acquire categories */ for (auto& [identifier, inputBind] : InputBindRegistry) diff --git a/src/Inputs/GameBinds/GameBindsHandler.cpp b/src/Inputs/GameBinds/GameBindsHandler.cpp index 151ac3c..807d894 100644 --- a/src/Inputs/GameBinds/GameBindsHandler.cpp +++ b/src/Inputs/GameBinds/GameBindsHandler.cpp @@ -640,19 +640,19 @@ void CGameBindsApi::OnUEInputBindChanged(void* aData) /* only process keyboard binds (for now) */ if (kbChange->Bind.DeviceType == 1) { return; } - InputBind kb{}; + InputBind ib{}; /* if key was unbound */ if (kbChange->Bind.DeviceType != 0) { - kb.Alt = kbChange->Bind.Modifiers & 0b0100; - kb.Ctrl = kbChange->Bind.Modifiers & 0b0010; - kb.Shift = kbChange->Bind.Modifiers & 0b0001; + ib.Alt = kbChange->Bind.Modifiers & 0b0100; + ib.Ctrl = kbChange->Bind.Modifiers & 0b0010; + ib.Shift = kbChange->Bind.Modifiers & 0b0001; - kb.Key = CGameBindsApi::GameBindCodeToScanCode(kbChange->Bind.Code); + ib.Code = CGameBindsApi::GameBindCodeToScanCode(kbChange->Bind.Code); } - UEInputBindUpdatesTarget->Set(kbChange->Identifier, kb, true); + UEInputBindUpdatesTarget->Set(kbChange->Identifier, ib, true); } CGameBindsApi::CGameBindsApi(CRawInputApi* aRawInputApi, CLogHandler* aLogger, CEventApi* aEventApi) @@ -706,67 +706,67 @@ void CGameBindsApi::InvokeAsync(EGameBinds aGameBind, int aDuration) void CGameBindsApi::Press(EGameBinds aGameBind) { - InputBind kb = this->Get(aGameBind); + InputBind ib = this->Get(aGameBind); - if (!kb.IsBound()) + if (!ib.IsBound()) { return; } KeyLParam key{}; key.RepeatCount = 1; - key.ScanCode = kb.Key; - key.ExtendedFlag = (kb.Key & 0xE000) != 0; + key.ScanCode = ib.Code; + key.ExtendedFlag = (ib.Code & 0xE000) != 0; key.Reserved = 0; - key.ContextCode = kb.Alt; + key.ContextCode = ib.Alt; key.PreviousKeyState = 0; key.TransitionState = 0; - if (kb.Alt) + if (ib.Alt) { this->RawInputApi->SendWndProcToGame(0, WM_SYSKEYDOWN, VK_MENU, GetKeyMessageLPARAM(VK_MENU, true, true)); } - if (kb.Ctrl) + if (ib.Ctrl) { this->RawInputApi->SendWndProcToGame(0, WM_KEYDOWN, VK_CONTROL, GetKeyMessageLPARAM(VK_CONTROL, true, false)); } - if (kb.Shift) + if (ib.Shift) { this->RawInputApi->SendWndProcToGame(0, WM_KEYDOWN, VK_SHIFT, GetKeyMessageLPARAM(VK_SHIFT, true, false)); } - this->RawInputApi->SendWndProcToGame(0, WM_KEYDOWN, MapVirtualKeyA(kb.Key, MAPVK_VSC_TO_VK), KMFToLParam(key)); + this->RawInputApi->SendWndProcToGame(0, WM_KEYDOWN, MapVirtualKeyA(ib.Code, MAPVK_VSC_TO_VK), KMFToLParam(key)); } void CGameBindsApi::Release(EGameBinds aGameBind) { - InputBind kb = this->Get(aGameBind); + InputBind ib = this->Get(aGameBind); - if (!kb.IsBound()) + if (!ib.IsBound()) { return; } KeyLParam key{}; key.RepeatCount = 1; - key.ScanCode = kb.Key; - key.ExtendedFlag = (kb.Key & 0xE000) != 0; + key.ScanCode = ib.Code; + key.ExtendedFlag = (ib.Code & 0xE000) != 0; key.Reserved = 0; - key.ContextCode = kb.Alt; + key.ContextCode = ib.Alt; key.PreviousKeyState = 1; key.TransitionState = 1; - this->RawInputApi->SendWndProcToGame(0, WM_KEYUP, MapVirtualKeyA(kb.Key, MAPVK_VSC_TO_VK), KMFToLParam(key)); + this->RawInputApi->SendWndProcToGame(0, WM_KEYUP, MapVirtualKeyA(ib.Code, MAPVK_VSC_TO_VK), KMFToLParam(key)); - if (kb.Alt) + if (ib.Alt) { this->RawInputApi->SendWndProcToGame(0, WM_SYSKEYUP, VK_MENU, GetKeyMessageLPARAM(VK_MENU, false, true)); } - if (kb.Ctrl) + if (ib.Ctrl) { this->RawInputApi->SendWndProcToGame(0, WM_KEYUP, VK_CONTROL, GetKeyMessageLPARAM(VK_CONTROL, false, false)); } - if (kb.Shift) + if (ib.Shift) { this->RawInputApi->SendWndProcToGame(0, WM_KEYUP, VK_SHIFT, GetKeyMessageLPARAM(VK_SHIFT, false, false)); } @@ -853,15 +853,15 @@ void CGameBindsApi::Load() continue; } - InputBind kb{}; - binding["Key"].get_to(kb.Key); - binding["Alt"].get_to(kb.Alt); - binding["Ctrl"].get_to(kb.Ctrl); - binding["Shift"].get_to(kb.Shift); + InputBind ib{}; + binding["Key"].get_to(ib.Code); + binding["Alt"].get_to(ib.Alt); + binding["Ctrl"].get_to(ib.Ctrl); + binding["Shift"].get_to(ib.Shift); EGameBinds identifier = binding["Identifier"].get(); - this->Registry[identifier] = kb; + this->Registry[identifier] = ib; } file.close(); @@ -882,18 +882,18 @@ void CGameBindsApi::Save() for (auto& it : this->Registry) { - InputBind kb = it.second; + InputBind ib = it.second; EGameBinds id = it.first; - if (!kb.IsBound()) { continue; } + if (!ib.IsBound()) { continue; } json binding = { {"Identifier", id}, - {"Key", kb.Key}, - {"Alt", kb.Alt}, - {"Ctrl", kb.Ctrl}, - {"Shift", kb.Shift} + {"Key", ib.Code}, + {"Alt", ib.Alt}, + {"Ctrl", ib.Ctrl}, + {"Shift", ib.Shift} }; InputBinds.push_back(binding); diff --git a/src/Inputs/GameBinds/GameBindsHandler.h b/src/Inputs/GameBinds/GameBindsHandler.h index b6e1ab5..b0e9c27 100644 --- a/src/Inputs/GameBinds/GameBindsHandler.h +++ b/src/Inputs/GameBinds/GameBindsHandler.h @@ -16,11 +16,9 @@ #include "EGameBinds.h" -#include "Inputs/RawInput/RawInputApi.h" -#include "Inputs/InputBinds/InputBind.h" - #include "Events/EventHandler.h" - +#include "Inputs/InputBinds/InputBind.h" +#include "Inputs/RawInput/RawInputApi.h" #include "Services/Logging/LogHandler.h" constexpr const char* CH_GAMEBINDS = "GameBinds"; diff --git a/src/Inputs/InputBinds/ActiveInputBind.h b/src/Inputs/InputBinds/ActiveInputBind.h deleted file mode 100644 index 8b0ed25..0000000 --- a/src/Inputs/InputBinds/ActiveInputBind.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ACTIVEINPUTBIND_H -#define ACTIVEINPUTBIND_H - -#include "InputBind.h" -#include "FuncDefs.h" - -typedef enum class EInputBindHandlerType -{ - None, - DownOnly, - DownAndRelease -} EIBHType; - -struct ActiveInputBind -{ - InputBind Bind; - EInputBindHandlerType HandlerType; - void* Handler; -}; - -#endif diff --git a/src/Inputs/InputBinds/EInputBindHandlerType.h b/src/Inputs/InputBinds/EInputBindHandlerType.h new file mode 100644 index 0000000..e988482 --- /dev/null +++ b/src/Inputs/InputBinds/EInputBindHandlerType.h @@ -0,0 +1,22 @@ +///---------------------------------------------------------------------------------------------------- +/// Copyright (c) Raidcore.GG - All rights reserved. +/// +/// Name : EInputBindHandlerType.h +/// Description : EInputBindHandlerType enum definition. +/// Authors : K. Bieniek +///---------------------------------------------------------------------------------------------------- + +#ifndef INPUTBINDHANDLERTYPE_H +#define INPUTBINDHANDLERTYPE_H + +///---------------------------------------------------------------------------------------------------- +/// EInputBindHandlerType Enum +///---------------------------------------------------------------------------------------------------- +typedef enum class EInputBindHandlerType +{ + None, + DownOnly, + DownAndRelease +} EIBHType; + +#endif diff --git a/src/Inputs/InputBinds/EInputBindType.h b/src/Inputs/InputBinds/EInputBindType.h new file mode 100644 index 0000000..3454808 --- /dev/null +++ b/src/Inputs/InputBinds/EInputBindType.h @@ -0,0 +1,22 @@ +///---------------------------------------------------------------------------------------------------- +/// Copyright (c) Raidcore.GG - All rights reserved. +/// +/// Name : EInputBindType.h +/// Description : EInputBindType enum definition. +/// Authors : K. Bieniek +///---------------------------------------------------------------------------------------------------- + +#ifndef INPUTBINDTYPE_H +#define INPUTBINDTYPE_H + +///---------------------------------------------------------------------------------------------------- +/// EInputBindType Enum +///---------------------------------------------------------------------------------------------------- +typedef enum class EInputBindType +{ + None, + Keyboard, + Mouse +} EIBType; + +#endif diff --git a/src/Inputs/InputBinds/FuncDefs.h b/src/Inputs/InputBinds/FuncDefs.h index 0f59e89..02f7c5b 100644 --- a/src/Inputs/InputBinds/FuncDefs.h +++ b/src/Inputs/InputBinds/FuncDefs.h @@ -5,11 +5,11 @@ typedef void (*INPUTBINDS_PROCESS)(const char* aIdentifier); typedef void (*INPUTBINDS_REGISTERWITHSTRING)(const char* aIdentifier, INPUTBINDS_PROCESS aInputBindHandler, const char* aInputBind); -typedef void (*INPUTBINDS_REGISTERWITHSTRUCT)(const char* aIdentifier, INPUTBINDS_PROCESS aInputBindHandler, InputBind aInputBind); +typedef void (*INPUTBINDS_REGISTERWITHSTRUCT)(const char* aIdentifier, INPUTBINDS_PROCESS aInputBindHandler, LegacyInputBind aInputBind); typedef void (*INPUTBINDS_PROCESS2)(const char* aIdentifier, bool aIsRelease); typedef void (*INPUTBINDS_REGISTERWITHSTRING2)(const char* aIdentifier, INPUTBINDS_PROCESS2 aInputBindHandler, const char* aInputBind); -typedef void (*INPUTBINDS_REGISTERWITHSTRUCT2)(const char* aIdentifier, INPUTBINDS_PROCESS2 aInputBindHandler, InputBind aInputBind); +typedef void (*INPUTBINDS_REGISTERWITHSTRUCT2)(const char* aIdentifier, INPUTBINDS_PROCESS2 aInputBindHandler, LegacyInputBind aInputBind); typedef void (*INPUTBINDS_INVOKE)(const char* aIdentifier, bool aIsRelease); diff --git a/src/Inputs/InputBinds/InputBind.cpp b/src/Inputs/InputBinds/InputBind.cpp index 63084e5..4add5bb 100644 --- a/src/Inputs/InputBinds/InputBind.cpp +++ b/src/Inputs/InputBinds/InputBind.cpp @@ -1,10 +1,22 @@ +///---------------------------------------------------------------------------------------------------- +/// Copyright (c) Raidcore.GG - All rights reserved. +/// +/// Name : InputBind.cpp +/// Description : InputBind struct definition. +/// Authors : K. Bieniek +///---------------------------------------------------------------------------------------------------- + #include "InputBind.h" -#include -#include -#include +InputBind::InputBind(LegacyInputBind aLegacyInputBind) +{ + Alt = aLegacyInputBind.Alt; + Ctrl = aLegacyInputBind.Ctrl; + Shift = aLegacyInputBind.Shift; -#include "InputBindHandler.h" + Type = EInputBindType::Keyboard; + Code = aLegacyInputBind.Key; +} bool InputBind::IsBound() { @@ -13,13 +25,14 @@ bool InputBind::IsBound() bool operator==(const InputBind& lhs, const InputBind& rhs) { - return lhs.Key == rhs.Key && - lhs.Alt == rhs.Alt && + return lhs.Alt == rhs.Alt && lhs.Ctrl == rhs.Ctrl && - lhs.Shift == rhs.Shift; + lhs.Shift == rhs.Shift && + lhs.Type == rhs.Type && + lhs.Code == rhs.Code; } bool operator!=(const InputBind& lhs, const InputBind& rhs) { return !(lhs == rhs); -} \ No newline at end of file +} diff --git a/src/Inputs/InputBinds/InputBind.h b/src/Inputs/InputBinds/InputBind.h index 7f7bd1a..155ebf0 100644 --- a/src/Inputs/InputBinds/InputBind.h +++ b/src/Inputs/InputBinds/InputBind.h @@ -1,19 +1,58 @@ +///---------------------------------------------------------------------------------------------------- +/// Copyright (c) Raidcore.GG - All rights reserved. +/// +/// Name : InputBind.h +/// Description : InputBind struct definition. +/// Authors : K. Bieniek +///---------------------------------------------------------------------------------------------------- + #ifndef INPUTBIND_H #define INPUTBIND_H -#include +#include "EInputBindType.h" -/* A structure holding information about a InputBind. */ -struct InputBind +///---------------------------------------------------------------------------------------------------- +/// LegacyInputBind Struct +/// Old Keybind struct used for backwards compatibility within APIs. +///---------------------------------------------------------------------------------------------------- +struct LegacyInputBind { unsigned short Key; bool Alt; bool Ctrl; bool Shift; +}; + +///---------------------------------------------------------------------------------------------------- +/// InputBind Struct +///---------------------------------------------------------------------------------------------------- +struct InputBind +{ + bool Alt; + bool Ctrl; + bool Shift; + EInputBindType Type; + unsigned short Code; + + InputBind() = default; + InputBind(bool aAlt, bool aCtrl, bool aShift, EInputBindType aType, unsigned short aCode) + : Alt{ aAlt } + , Ctrl{ aCtrl } + , Shift{ aShift } + , Type{ aType } + , Code{ aCode } + {} + InputBind(LegacyInputBind aLegacyInputBind); + + ///---------------------------------------------------------------------------------------------------- + /// IsBound: + /// Returns true if this input bind has any values set. + ///---------------------------------------------------------------------------------------------------- bool IsBound(); }; bool operator==(const InputBind& lhs, const InputBind& rhs); bool operator!=(const InputBind& lhs, const InputBind& rhs); -#endif \ No newline at end of file + +#endif diff --git a/src/Inputs/InputBinds/InputBindHandler.cpp b/src/Inputs/InputBinds/InputBindHandler.cpp index 65c4529..5ea69a0 100644 --- a/src/Inputs/InputBinds/InputBindHandler.cpp +++ b/src/Inputs/InputBinds/InputBindHandler.cpp @@ -15,12 +15,14 @@ #include "Consts.h" #include "Index.h" -#include "Shared.h" #include "State.h" #include "Util/Strings.h" #include "Util/Inputs.h" +/* FIXME: remove this -> DI */ +#include "Shared.h" + #include "nlohmann/json.hpp" using json = nlohmann::json; @@ -31,7 +33,7 @@ namespace InputBinds InputBindApi->Register(aIdentifier, EInputBindHandlerType::DownOnly, aInputBindHandler, aInputBind); } - void ADDONAPI_RegisterWithStruct(const char* aIdentifier, INPUTBINDS_PROCESS aInputBindHandler, InputBind aInputBind) + void ADDONAPI_RegisterWithStruct(const char* aIdentifier, INPUTBINDS_PROCESS aInputBindHandler, LegacyInputBind aInputBind) { InputBindApi->Register(aIdentifier, EInputBindHandlerType::DownOnly, aInputBindHandler, aInputBind); } @@ -41,7 +43,7 @@ namespace InputBinds InputBindApi->Register(aIdentifier, EInputBindHandlerType::DownAndRelease, aInputBindHandler, aInputBind); } - void ADDONAPI_RegisterWithStruct2(const char* aIdentifier, INPUTBINDS_PROCESS2 aInputBindHandler, InputBind aInputBind) + void ADDONAPI_RegisterWithStruct2(const char* aIdentifier, INPUTBINDS_PROCESS2 aInputBindHandler, LegacyInputBind aInputBind) { InputBindApi->Register(aIdentifier, EInputBindHandlerType::DownAndRelease, aInputBindHandler, aInputBind); } @@ -142,7 +144,7 @@ InputBind CInputBindApi::KBFromString(std::string aInputBind) { if (it->second == aInputBind) { - kb.Key = it->first; + kb.Code = it->first; break; } } @@ -157,7 +159,7 @@ std::string CInputBindApi::KBToString(InputBind aInputBind, bool padded) BuildscanCodeLookupTable(); } - if (!aInputBind.Key) { return "(null)"; } + if (!aInputBind.Code) { return "(null)"; } char* buff = new char[100]; std::string str; @@ -184,16 +186,16 @@ std::string CInputBindApi::KBToString(InputBind aInputBind, bool padded) } HKL hkl = GetKeyboardLayout(0); - UINT vk = MapVirtualKeyA(aInputBind.Key, MAPVK_VSC_TO_VK); + UINT vk = MapVirtualKeyA(aInputBind.Code, MAPVK_VSC_TO_VK); if (vk >= 65 && vk <= 90 || vk >= 48 && vk <= 57) { - GetKeyNameTextA(aInputBind.Key << 16, buff, 100); + GetKeyNameTextA(aInputBind.Code << 16, buff, 100); str.append(buff); } else { - auto it = ScancodeLookupTable.find(aInputBind.Key); + auto it = ScancodeLookupTable.find(aInputBind.Code); if (it != ScancodeLookupTable.end()) { str.append(it->second); @@ -207,8 +209,10 @@ std::string CInputBindApi::KBToString(InputBind aInputBind, bool padded) return String::ConvertMBToUTF8(str); } -CInputBindApi::CInputBindApi() +CInputBindApi::CInputBindApi(CLogHandler* aLogger) { + this->Logger = aLogger; + this->Load(); } @@ -238,12 +242,12 @@ UINT CInputBindApi::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) kb.Alt = this->IsAltHeld; kb.Ctrl = this->IsCtrlHeld; kb.Shift = this->IsShiftHeld; - kb.Key = keylp.GetScanCode(); + kb.Code = keylp.GetScanCode(); // if shift, ctrl or alt set key to 0 if (wParam == VK_SHIFT || wParam == VK_CONTROL || wParam == VK_MENU) { - kb.Key = 0; + kb.Code = 0; } if (kb == InputBind{}) @@ -272,9 +276,9 @@ UINT CInputBindApi::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) break; } - if (std::find(this->HeldKeys.begin(), this->HeldKeys.end(), kb.Key) == this->HeldKeys.end()) + if (std::find(this->HeldKeys.begin(), this->HeldKeys.end(), kb.Code) == this->HeldKeys.end()) { - this->HeldKeys.push_back(kb.Key); + this->HeldKeys.push_back(kb.Code); } /* track the actual bind/id combo too */ @@ -341,7 +345,7 @@ UINT CInputBindApi::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) KeyLParam keylp = LParamToKMF(lParam); unsigned short scanCode = keylp.GetScanCode(); - if (scanCode == bind.second.Bind.Key) + if (scanCode == bind.second.Bind.Code) { this->Invoke(bind.first, true); this->HeldKeys.erase(std::find(this->HeldKeys.begin(), this->HeldKeys.end(), scanCode)); @@ -401,7 +405,7 @@ void CInputBindApi::Register(const char* aIdentifier, EInputBindHandlerType aInp /* check if this InputBind is not already set */ if (it == Registry.end()) { - this->Registry[str] = ActiveInputBind{ + this->Registry[str] = ManagedInputBind{ requestedBind, aInputBindHandlerType, aInputBindHandler @@ -530,7 +534,7 @@ int CInputBindApi::Verify(void* aStartAddress, void* aEndAddress) return refCounter; } -std::map CInputBindApi::GetRegistry() const +std::map CInputBindApi::GetRegistry() const { const std::lock_guard lock(this->Mutex); @@ -587,7 +591,7 @@ void CInputBindApi::Load() } InputBind kb{}; - binding["Key"].get_to(kb.Key); + binding["Key"].get_to(kb.Code); binding["Alt"].get_to(kb.Alt); binding["Ctrl"].get_to(kb.Ctrl); binding["Shift"].get_to(kb.Shift); @@ -619,7 +623,7 @@ void CInputBindApi::Save() json binding = { {"Identifier", id}, - {"Key", kb.Key}, + {"Key", kb.Code}, {"Alt", kb.Alt}, {"Ctrl", kb.Ctrl}, {"Shift", kb.Shift} diff --git a/src/Inputs/InputBinds/InputBindHandler.h b/src/Inputs/InputBinds/InputBindHandler.h index 82ac60f..7bf12af 100644 --- a/src/Inputs/InputBinds/InputBindHandler.h +++ b/src/Inputs/InputBinds/InputBindHandler.h @@ -10,15 +10,16 @@ #define INPUTBINDHANDLER_H #include -#include #include +#include #include #include #include "FuncDefs.h" - -#include "ActiveInputBind.h" #include "InputBind.h" +#include "ManagedInputBind.h" + +#include "Services/Logging/LogHandler.h" constexpr const char* CH_INPUTBINDS = "InputBinds"; @@ -37,7 +38,7 @@ namespace InputBinds /// ADDONAPI_RegisterWithStruct: /// [Revision 1] Addon API wrapper function for Register from struct. ///---------------------------------------------------------------------------------------------------- - void ADDONAPI_RegisterWithStruct(const char* aIdentifier, INPUTBINDS_PROCESS aInputBindHandler, InputBind aInputBind); + void ADDONAPI_RegisterWithStruct(const char* aIdentifier, INPUTBINDS_PROCESS aInputBindHandler, LegacyInputBind aInputBind); ///---------------------------------------------------------------------------------------------------- /// ADDONAPI_RegisterWithString: @@ -49,7 +50,7 @@ namespace InputBinds /// ADDONAPI_RegisterWithStruct: /// [Revision 2] Addon API wrapper function for Register from struct. ///---------------------------------------------------------------------------------------------------- - void ADDONAPI_RegisterWithStruct2(const char* aIdentifier, INPUTBINDS_PROCESS2 aInputBindHandler, InputBind aInputBind); + void ADDONAPI_RegisterWithStruct2(const char* aIdentifier, INPUTBINDS_PROCESS2 aInputBindHandler, LegacyInputBind aInputBind); ///---------------------------------------------------------------------------------------------------- /// ADDONAPI_InvokeInputBind: @@ -92,7 +93,7 @@ class CInputBindApi ///---------------------------------------------------------------------------------------------------- /// ctor ///---------------------------------------------------------------------------------------------------- - CInputBindApi(); + CInputBindApi(CLogHandler* aLogger); ///---------------------------------------------------------------------------------------------------- /// dtor ///---------------------------------------------------------------------------------------------------- @@ -159,7 +160,7 @@ class CInputBindApi /// GetRegistry: /// Returns a copy of the registry. ///---------------------------------------------------------------------------------------------------- - std::map GetRegistry() const; + std::map GetRegistry() const; ///---------------------------------------------------------------------------------------------------- /// GetCapturedInputBind: @@ -180,17 +181,19 @@ class CInputBindApi void EndCapturing(); private: + CLogHandler* Logger; + mutable std::mutex Mutex; - std::map Registry; + std::map Registry; bool IsCapturing; - InputBind CapturedInputBind; + InputBind CapturedInputBind; bool IsAltHeld; bool IsCtrlHeld; bool IsShiftHeld; std::vector HeldKeys; - std::map HeldInputBinds; + std::map HeldInputBinds; ///---------------------------------------------------------------------------------------------------- /// Load: diff --git a/src/Inputs/InputBinds/ManagedInputBind.h b/src/Inputs/InputBinds/ManagedInputBind.h new file mode 100644 index 0000000..5d1886e --- /dev/null +++ b/src/Inputs/InputBinds/ManagedInputBind.h @@ -0,0 +1,25 @@ +///---------------------------------------------------------------------------------------------------- +/// Copyright (c) Raidcore.GG - All rights reserved. +/// +/// Name : ManagedInputBind.h +/// Description : ManagedInputBind struct definition. +/// Authors : K. Bieniek +///---------------------------------------------------------------------------------------------------- + +#ifndef MANAGEDINPUTBIND_H +#define MANAGEDINPUTBIND_H + +#include "InputBind.h" +#include "EInputBindHandlerType.h" + +///---------------------------------------------------------------------------------------------------- +/// ManagedInputBind Struct +///---------------------------------------------------------------------------------------------------- +struct ManagedInputBind +{ + InputBind Bind; + EInputBindHandlerType HandlerType; + void* Handler; +}; + +#endif diff --git a/src/Main.cpp b/src/Main.cpp index a2d47de..fc0e52d 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -130,7 +130,7 @@ namespace Main MH_Initialize(); - InputBindApi = new CInputBindApi(); + InputBindApi = new CInputBindApi(Logger); GameBindsApi = new CGameBindsApi(RawInputApi, Logger, EventApi); Settings::Load();