diff --git a/FRAMEWORK_PIN b/FRAMEWORK_PIN new file mode 100644 index 00000000..3a2189ad --- /dev/null +++ b/FRAMEWORK_PIN @@ -0,0 +1,3 @@ +# Framework source required by the unified IInput adapter migration. +# Framework PR #292; replace with its merged commit before release. +689c27139ba8e0123e33cfb54f869d27f15c7001 diff --git a/code/client/src/core/application.h b/code/client/src/core/application.h index d17c8832..a8b88b0c 100644 --- a/code/client/src/core/application.h +++ b/code/client/src/core/application.h @@ -98,6 +98,10 @@ namespace MafiaMP::Core { return _input.get(); } + bool IsLocalInputAvailable() const override { + return !AreControlsLocked() && Framework::Integrations::Client::Instance::IsLocalInputAvailable(); + } + std::shared_ptr GetInput() const { return _input; } diff --git a/code/client/src/core/ui/devs/camera_studio.cpp b/code/client/src/core/ui/devs/camera_studio.cpp index 6a79107b..f041419f 100644 --- a/code/client/src/core/ui/devs/camera_studio.cpp +++ b/code/client/src/core/ui/devs/camera_studio.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "camera_studio.h" #include @@ -187,8 +190,9 @@ namespace MafiaMP::Core::UI::Devs { POINT mouse = {}; GetCursorPos(&mouse); - if (!_frozen) { - if ((GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0) { + const auto *input = Framework::CoreModules::GetInput(); + if (!_frozen && input) { + if (input->IsKeyDown(FW_KEY_RBUTTON)) { _yaw += static_cast(mouse.x - _lastMousePos.x) * _sensitivity; _pitch -= static_cast(mouse.y - _lastMousePos.y) * _sensitivity; _pitch = std::clamp(_pitch, -kMaxPitch, kMaxPitch); @@ -198,10 +202,10 @@ namespace MafiaMP::Core::UI::Devs { const SDK::ue::sys::math::C_Vector right = {std::cos(_yaw), -std::sin(_yaw), 0.0f}; float speed = _moveSpeed; - if (GetAsyncKeyState(VK_SHIFT) & 0x8000) { + if (input->IsKeyDown(FW_KEY_SHIFT)) { speed *= 3.0f; } - if (GetAsyncKeyState(VK_CONTROL) & 0x8000) { + if (input->IsKeyDown(FW_KEY_CONTROL)) { speed *= 0.25f; } const float step = speed * deltaTime; @@ -212,22 +216,22 @@ namespace MafiaMP::Core::UI::Devs { _position.z += v.z * s; }; - if (GetAsyncKeyState('W') & 0x8000) { + if (input->IsKeyDown('W')) { move(forward, step); } - if (GetAsyncKeyState('S') & 0x8000) { + if (input->IsKeyDown('S')) { move(forward, -step); } - if (GetAsyncKeyState('D') & 0x8000) { + if (input->IsKeyDown('D')) { move(right, step); } - if (GetAsyncKeyState('A') & 0x8000) { + if (input->IsKeyDown('A')) { move(right, -step); } - if (GetAsyncKeyState(VK_SPACE) & 0x8000) { + if (input->IsKeyDown(FW_KEY_SPACE)) { _position.z += step; } - if (GetAsyncKeyState('C') & 0x8000) { + if (input->IsKeyDown('C')) { _position.z -= step; } } diff --git a/code/client/src/game/helpers/game_input.cpp b/code/client/src/game/helpers/game_input.cpp index e40216d7..a8a13c6d 100644 --- a/code/client/src/game/helpers/game_input.cpp +++ b/code/client/src/game/helpers/game_input.cpp @@ -3,54 +3,6 @@ #include "core/application.h" namespace MafiaMP::Game { - void GameInput::Update() { - for (int i = 0; i < 256; i++) { - _keysPressed[i] = false; - _keysReleased[i] = false; - } - - for (int i = 0; i < 5; i++) { - _buttonsPressed[i] = false; - _buttonsReleased[i] = false; - } - } - - uint32_t GameInput::MapKey(uint32_t key) const { - return key; // we map WndProc VK keys 1:1 to our input keys - } - - void GameInput::ProcessEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - switch (msg) { - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - _keysDown[wParam] = true; - _keysPressed[wParam] = true; - break; - case WM_KEYUP: - case WM_SYSKEYUP: - _keysDown[wParam] = false; - _keysReleased[wParam] = true; - break; - case WM_LBUTTONDOWN: - case WM_RBUTTONDOWN: - case WM_MBUTTONDOWN: - _buttonsDown[wParam] = true; - _buttonsPressed[wParam] = true; - break; - case WM_LBUTTONUP: - case WM_RBUTTONUP: - case WM_MBUTTONUP: - _buttonsDown[wParam] = false; - _buttonsReleased[wParam] = true; - break; - case WM_MOUSEMOVE: - _mousePosition[0] = LOWORD(lParam); - _mousePosition[1] = HIWORD(lParam); - break; - default: break; - } - } - bool GameInput::IsInputLocked() const { return Core::gApplication->AreControlsLocked(); } diff --git a/code/client/src/game/helpers/game_input.h b/code/client/src/game/helpers/game_input.h index d1e6d24e..92e681b8 100644 --- a/code/client/src/game/helpers/game_input.h +++ b/code/client/src/game/helpers/game_input.h @@ -2,20 +2,14 @@ #include -#include +#include namespace MafiaMP::Game { - class GameInput: public Framework::Input::IInput { + class GameInput final: public Framework::Input::WindowInput { public: GameInput() {} ~GameInput() = default; - void Update() override; - - void GetMousePosition(int &x, int &y) const override { - x = _mousePosition[0]; - y = _mousePosition[1]; - }; void SetMousePosition(int x, int y) override {}; void SetMouseVisible(bool visible) override { SetInputLocked(visible); @@ -29,68 +23,5 @@ namespace MafiaMP::Game { }; void SetInputLocked(bool locked) override; bool IsInputLocked() const override; - - bool IsKeyDown(int key) const override { - if (key < 0 || key > 255) { - return false; - } - return _keysDown[MapKey(key)]; - }; - bool IsKeyUp(int key) const override { - if (key < 0 || key > 255) { - return false; - } - return !_keysDown[MapKey(key)]; - }; - bool IsKeyPressed(int key) const override { - if (key < 0 || key > 255) { - return false; - } - return _keysPressed[MapKey(key)]; - }; - bool IsKeyReleased(int key) const override { - if (key < 0 || key > 255) { - return false; - } - return _keysReleased[MapKey(key)]; - }; - - bool IsMouseButtonDown(int button) const override { - if (button < 0 || button > 4) { - return false; - } - return _buttonsDown[button]; - }; - bool IsMouseButtonUp(int button) const override { - if (button < 0 || button > 4) { - return false; - } - return !_buttonsDown[button]; - }; - bool IsMouseButtonPressed(int button) const override { - if (button < 0 || button > 4) { - return false; - } - return _buttonsPressed[button]; - }; - bool IsMouseButtonReleased(int button) const override { - if (button < 0 || button > 4) { - return false; - } - return _buttonsReleased[button]; - }; - - uint32_t MapKey(uint32_t key) const override; - - void ProcessEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); - - private: - bool _keysDown[256] = {false}; - bool _keysPressed[256] = {false}; - bool _keysReleased[256] = {false}; - bool _buttonsDown[5] = {false}; - bool _buttonsPressed[5] = {false}; - bool _buttonsReleased[5] = {false}; - int _mousePosition[2] = {}; }; } // namespace MafiaMP::Game