From 4c6f2c2547e1d97f12ebe708fac693a6183bbc45 Mon Sep 17 00:00:00 2001 From: german77 Date: Mon, 20 Sep 2021 16:57:55 -0500 Subject: input_common: Move touch and analog from button. Move udp protocol --- src/input_common/CMakeLists.txt | 12 +- src/input_common/analog_from_button.cpp | 238 --------------------- src/input_common/analog_from_button.h | 31 --- src/input_common/helpers/stick_from_buttons.cpp | 270 ++++++++++++++++++++++++ src/input_common/helpers/stick_from_buttons.h | 31 +++ src/input_common/helpers/touch_from_buttons.cpp | 70 ++++++ src/input_common/helpers/touch_from_buttons.h | 22 ++ src/input_common/helpers/udp_protocol.cpp | 78 +++++++ src/input_common/helpers/udp_protocol.h | 259 +++++++++++++++++++++++ src/input_common/main.cpp | 8 - src/input_common/touch_from_button.cpp | 53 ----- src/input_common/touch_from_button.h | 23 -- src/input_common/udp/client.cpp | 2 +- src/input_common/udp/protocol.cpp | 78 ------- src/input_common/udp/protocol.h | 259 ----------------------- 15 files changed, 737 insertions(+), 697 deletions(-) delete mode 100755 src/input_common/analog_from_button.cpp delete mode 100755 src/input_common/analog_from_button.h create mode 100644 src/input_common/helpers/stick_from_buttons.cpp create mode 100644 src/input_common/helpers/stick_from_buttons.h create mode 100644 src/input_common/helpers/touch_from_buttons.cpp create mode 100644 src/input_common/helpers/touch_from_buttons.h create mode 100644 src/input_common/helpers/udp_protocol.cpp create mode 100644 src/input_common/helpers/udp_protocol.h delete mode 100644 src/input_common/touch_from_button.cpp delete mode 100644 src/input_common/touch_from_button.h delete mode 100644 src/input_common/udp/protocol.cpp delete mode 100644 src/input_common/udp/protocol.h diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 72f1e0f4a..90e7618ce 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -1,8 +1,12 @@ add_library(input_common STATIC - analog_from_button.cpp - analog_from_button.h keyboard.cpp keyboard.h + helpers/stick_from_buttons.cpp + helpers/stick_from_buttons.h + helpers/touch_from_buttons.cpp + helpers/touch_from_buttons.h + helpers/udp_protocol.cpp + helpers/udp_protocol.h input_engine.cpp input_engine.h input_mapping.cpp @@ -15,8 +19,6 @@ add_library(input_common STATIC motion_from_button.h motion_input.cpp motion_input.h - touch_from_button.cpp - touch_from_button.h gcadapter/gc_adapter.cpp gcadapter/gc_adapter.h gcadapter/gc_poller.cpp @@ -33,8 +35,6 @@ add_library(input_common STATIC tas/tas_poller.h udp/client.cpp udp/client.h - udp/protocol.cpp - udp/protocol.h udp/udp.cpp udp/udp.h ) diff --git a/src/input_common/analog_from_button.cpp b/src/input_common/analog_from_button.cpp deleted file mode 100755 index 2fafd077f..000000000 --- a/src/input_common/analog_from_button.cpp +++ /dev/null @@ -1,238 +0,0 @@ -// Copyright 2017 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include -#include -#include -#include -#include "common/math_util.h" -#include "common/settings.h" -#include "input_common/analog_from_button.h" - -namespace InputCommon { - -class Analog final : public Input::AnalogDevice { -public: - using Button = std::unique_ptr; - - Analog(Button up_, Button down_, Button left_, Button right_, Button modifier_, - float modifier_scale_, float modifier_angle_) - : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), - right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), - modifier_angle(modifier_angle_) { - Input::InputCallback callbacks{ - [this]([[maybe_unused]] bool status) { UpdateStatus(); }}; - up->SetCallback(callbacks); - down->SetCallback(callbacks); - left->SetCallback(callbacks); - right->SetCallback(callbacks); - modifier->SetCallback(callbacks); - } - - bool IsAngleGreater(float old_angle, float new_angle) const { - constexpr float TAU = Common::PI * 2.0f; - // Use wider angle to ease the transition. - constexpr float aperture = TAU * 0.15f; - const float top_limit = new_angle + aperture; - return (old_angle > new_angle && old_angle <= top_limit) || - (old_angle + TAU > new_angle && old_angle + TAU <= top_limit); - } - - bool IsAngleSmaller(float old_angle, float new_angle) const { - constexpr float TAU = Common::PI * 2.0f; - // Use wider angle to ease the transition. - constexpr float aperture = TAU * 0.15f; - const float bottom_limit = new_angle - aperture; - return (old_angle >= bottom_limit && old_angle < new_angle) || - (old_angle - TAU >= bottom_limit && old_angle - TAU < new_angle); - } - - float GetAngle(std::chrono::time_point now) const { - constexpr float TAU = Common::PI * 2.0f; - float new_angle = angle; - - auto time_difference = static_cast( - std::chrono::duration_cast(now - last_update).count()); - time_difference /= 1000.0f * 1000.0f; - if (time_difference > 0.5f) { - time_difference = 0.5f; - } - - if (IsAngleGreater(new_angle, goal_angle)) { - new_angle -= modifier_angle * time_difference; - if (new_angle < 0) { - new_angle += TAU; - } - if (!IsAngleGreater(new_angle, goal_angle)) { - return goal_angle; - } - } else if (IsAngleSmaller(new_angle, goal_angle)) { - new_angle += modifier_angle * time_difference; - if (new_angle >= TAU) { - new_angle -= TAU; - } - if (!IsAngleSmaller(new_angle, goal_angle)) { - return goal_angle; - } - } else { - return goal_angle; - } - return new_angle; - } - - void SetGoalAngle(bool r, bool l, bool u, bool d) { - // Move to the right - if (r && !u && !d) { - goal_angle = 0.0f; - } - - // Move to the upper right - if (r && u && !d) { - goal_angle = Common::PI * 0.25f; - } - - // Move up - if (u && !l && !r) { - goal_angle = Common::PI * 0.5f; - } - - // Move to the upper left - if (l && u && !d) { - goal_angle = Common::PI * 0.75f; - } - - // Move to the left - if (l && !u && !d) { - goal_angle = Common::PI; - } - - // Move to the bottom left - if (l && !u && d) { - goal_angle = Common::PI * 1.25f; - } - - // Move down - if (d && !l && !r) { - goal_angle = Common::PI * 1.5f; - } - - // Move to the bottom right - if (r && !u && d) { - goal_angle = Common::PI * 1.75f; - } - } - - void UpdateStatus() { - const float coef = modifier->GetStatus() ? modifier_scale : 1.0f; - - bool r = right->GetStatus(); - bool l = left->GetStatus(); - bool u = up->GetStatus(); - bool d = down->GetStatus(); - - // Eliminate contradictory movements - if (r && l) { - r = false; - l = false; - } - if (u && d) { - u = false; - d = false; - } - - // Move if a key is pressed - if (r || l || u || d) { - amplitude = coef; - } else { - amplitude = 0; - } - - const auto now = std::chrono::steady_clock::now(); - const auto time_difference = static_cast( - std::chrono::duration_cast(now - last_update).count()); - - if (time_difference < 10) { - // Disable analog mode if inputs are too fast - SetGoalAngle(r, l, u, d); - angle = goal_angle; - } else { - angle = GetAngle(now); - SetGoalAngle(r, l, u, d); - } - - last_update = now; - } - - std::tuple GetStatus() const override { - if (Settings::values.emulate_analog_keyboard) { - const auto now = std::chrono::steady_clock::now(); - float angle_ = GetAngle(now); - return std::make_tuple(std::cos(angle_) * amplitude, std::sin(angle_) * amplitude); - } - constexpr float SQRT_HALF = 0.707106781f; - int x = 0, y = 0; - if (right->GetStatus()) { - ++x; - } - if (left->GetStatus()) { - --x; - } - if (up->GetStatus()) { - ++y; - } - if (down->GetStatus()) { - --y; - } - const float coef = modifier->GetStatus() ? modifier_scale : 1.0f; - return std::make_tuple(static_cast(x) * coef * (y == 0 ? 1.0f : SQRT_HALF), - static_cast(y) * coef * (x == 0 ? 1.0f : SQRT_HALF)); - } - - Input::AnalogProperties GetAnalogProperties() const override { - return {modifier_scale, 1.0f, 0.5f}; - } - - bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { - switch (direction) { - case Input::AnalogDirection::RIGHT: - return right->GetStatus(); - case Input::AnalogDirection::LEFT: - return left->GetStatus(); - case Input::AnalogDirection::UP: - return up->GetStatus(); - case Input::AnalogDirection::DOWN: - return down->GetStatus(); - } - return false; - } - -private: - Button up; - Button down; - Button left; - Button right; - Button modifier; - float modifier_scale; - float modifier_angle; - float angle{}; - float goal_angle{}; - float amplitude{}; - std::chrono::time_point last_update; -}; - -std::unique_ptr AnalogFromButton::Create(const Common::ParamPackage& params) { - const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); - auto up = Input::CreateDevice(params.Get("up", null_engine)); - auto down = Input::CreateDevice(params.Get("down", null_engine)); - auto left = Input::CreateDevice(params.Get("left", null_engine)); - auto right = Input::CreateDevice(params.Get("right", null_engine)); - auto modifier = Input::CreateDevice(params.Get("modifier", null_engine)); - auto modifier_scale = params.Get("modifier_scale", 0.5f); - auto modifier_angle = params.Get("modifier_angle", 5.5f); - return std::make_unique(std::move(up), std::move(down), std::move(left), - std::move(right), std::move(modifier), modifier_scale, - modifier_angle); -} - -} // namespace InputCommon diff --git a/src/input_common/analog_from_button.h b/src/input_common/analog_from_button.h deleted file mode 100755 index bbd583dd9..000000000 --- a/src/input_common/analog_from_button.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2017 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include -#include "core/frontend/input.h" - -namespace InputCommon { - -/** - * An analog device factory that takes direction button devices and combines them into a analog - * device. - */ -class AnalogFromButton final : public Input::Factory { -public: - /** - * Creates an analog device from direction button devices - * @param params contains parameters for creating the device: - * - "up": a serialized ParamPackage for creating a button device for up direction - * - "down": a serialized ParamPackage for creating a button device for down direction - * - "left": a serialized ParamPackage for creating a button device for left direction - * - "right": a serialized ParamPackage for creating a button device for right direction - * - "modifier": a serialized ParamPackage for creating a button device as the modifier - * - "modifier_scale": a float for the multiplier the modifier gives to the position - */ - std::unique_ptr Create(const Common::ParamPackage& params) override; -}; - -} // namespace InputCommon diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp new file mode 100644 index 000000000..38f150746 --- /dev/null +++ b/src/input_common/helpers/stick_from_buttons.cpp @@ -0,0 +1,270 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include "common/math_util.h" +#include "common/settings.h" +#include "input_common/helpers/stick_from_buttons.h" + +namespace InputCommon { + +class Stick final : public Input::InputDevice { +public: + using Button = std::unique_ptr; + + Stick(Button up_, Button down_, Button left_, Button right_, Button modifier_, + float modifier_scale_, float modifier_angle_) + : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), + right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), + modifier_angle(modifier_angle_) { + Input::InputCallback button_up_callback{ + [this](Input::CallbackStatus callback_) { UpdateUpButtonStatus(callback_); }}; + Input::InputCallback button_down_callback{ + [this](Input::CallbackStatus callback_) { UpdateDownButtonStatus(callback_); }}; + Input::InputCallback button_left_callback{ + [this](Input::CallbackStatus callback_) { UpdateLeftButtonStatus(callback_); }}; + Input::InputCallback button_right_callback{ + [this](Input::CallbackStatus callback_) { UpdateRightButtonStatus(callback_); }}; + Input::InputCallback button_modifier_callback{ + [this](Input::CallbackStatus callback_) { UpdateModButtonStatus(callback_); }}; + up->SetCallback(button_up_callback); + down->SetCallback(button_down_callback); + left->SetCallback(button_left_callback); + right->SetCallback(button_right_callback); + modifier->SetCallback(button_modifier_callback); + } + + bool IsAngleGreater(float old_angle, float new_angle) const { + constexpr float TAU = Common::PI * 2.0f; + // Use wider angle to ease the transition. + constexpr float aperture = TAU * 0.15f; + const float top_limit = new_angle + aperture; + return (old_angle > new_angle && old_angle <= top_limit) || + (old_angle + TAU > new_angle && old_angle + TAU <= top_limit); + } + + bool IsAngleSmaller(float old_angle, float new_angle) const { + constexpr float TAU = Common::PI * 2.0f; + // Use wider angle to ease the transition. + constexpr float aperture = TAU * 0.15f; + const float bottom_limit = new_angle - aperture; + return (old_angle >= bottom_limit && old_angle < new_angle) || + (old_angle - TAU >= bottom_limit && old_angle - TAU < new_angle); + } + + float GetAngle(std::chrono::time_point now) const { + constexpr float TAU = Common::PI * 2.0f; + float new_angle = angle; + + auto time_difference = static_cast( + std::chrono::duration_cast(now - last_update).count()); + time_difference /= 1000.0f * 1000.0f; + if (time_difference > 0.5f) { + time_difference = 0.5f; + } + + if (IsAngleGreater(new_angle, goal_angle)) { + new_angle -= modifier_angle * time_difference; + if (new_angle < 0) { + new_angle += TAU; + } + if (!IsAngleGreater(new_angle, goal_angle)) { + return goal_angle; + } + } else if (IsAngleSmaller(new_angle, goal_angle)) { + new_angle += modifier_angle * time_difference; + if (new_angle >= TAU) { + new_angle -= TAU; + } + if (!IsAngleSmaller(new_angle, goal_angle)) { + return goal_angle; + } + } else { + return goal_angle; + } + return new_angle; + } + + void SetGoalAngle(bool r, bool l, bool u, bool d) { + // Move to the right + if (r && !u && !d) { + goal_angle = 0.0f; + } + + // Move to the upper right + if (r && u && !d) { + goal_angle = Common::PI * 0.25f; + } + + // Move up + if (u && !l && !r) { + goal_angle = Common::PI * 0.5f; + } + + // Move to the upper left + if (l && u && !d) { + goal_angle = Common::PI * 0.75f; + } + + // Move to the left + if (l && !u && !d) { + goal_angle = Common::PI; + } + + // Move to the bottom left + if (l && !u && d) { + goal_angle = Common::PI * 1.25f; + } + + // Move down + if (d && !l && !r) { + goal_angle = Common::PI * 1.5f; + } + + // Move to the bottom right + if (r && !u && d) { + goal_angle = Common::PI * 1.75f; + } + } + + void UpdateUpButtonStatus(Input::CallbackStatus button_callback) { + up_status = button_callback.button_status.value; + UpdateStatus(); + } + + void UpdateDownButtonStatus(Input::CallbackStatus button_callback) { + down_status = button_callback.button_status.value; + UpdateStatus(); + } + + void UpdateLeftButtonStatus(Input::CallbackStatus button_callback) { + left_status = button_callback.button_status.value; + UpdateStatus(); + } + + void UpdateRightButtonStatus(Input::CallbackStatus button_callback) { + right_status = button_callback.button_status.value; + UpdateStatus(); + } + + void UpdateModButtonStatus(Input::CallbackStatus button_callback) { + modifier_status = button_callback.button_status.value; + UpdateStatus(); + } + + void UpdateStatus() { + const float coef = modifier_status ? modifier_scale : 1.0f; + + bool r = right_status; + bool l = left_status; + bool u = up_status; + bool d = down_status; + + // Eliminate contradictory movements + if (r && l) { + r = false; + l = false; + } + if (u && d) { + u = false; + d = false; + } + + // Move if a key is pressed + if (r || l || u || d) { + amplitude = coef; + } else { + amplitude = 0; + } + + const auto now = std::chrono::steady_clock::now(); + const auto time_difference = static_cast( + std::chrono::duration_cast(now - last_update).count()); + + if (time_difference < 10) { + // Disable analog mode if inputs are too fast + SetGoalAngle(r, l, u, d); + angle = goal_angle; + } else { + angle = GetAngle(now); + SetGoalAngle(r, l, u, d); + } + + last_update = now; + Input::CallbackStatus status{ + .type = Input::InputType::Stick, + .stick_status = GetStatus(), + }; + TriggerOnChange(status); + } + + Input::StickStatus GetStatus() const { + Input::StickStatus status{}; + status.x.properties = properties; + status.y.properties = properties; + if (Settings::values.emulate_analog_keyboard) { + const auto now = std::chrono::steady_clock::now(); + float angle_ = GetAngle(now); + status.x.raw_value = std::cos(angle_) * amplitude; + status.y.raw_value = std::sin(angle_) * amplitude; + return status; + } + constexpr float SQRT_HALF = 0.707106781f; + int x = 0, y = 0; + if (right_status) { + ++x; + } + if (left_status) { + --x; + } + if (up_status) { + ++y; + } + if (down_status) { + --y; + } + const float coef = modifier_status ? modifier_scale : 1.0f; + status.x.raw_value = static_cast(x) * coef * (y == 0 ? 1.0f : SQRT_HALF); + status.y.raw_value = static_cast(y) * coef * (x == 0 ? 1.0f : SQRT_HALF); + return status; + } + +private: + Button up; + Button down; + Button left; + Button right; + Button modifier; + float modifier_scale; + float modifier_angle; + float angle{}; + float goal_angle{}; + float amplitude{}; + bool up_status; + bool down_status; + bool left_status; + bool right_status; + bool modifier_status; + const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; + std::chrono::time_point last_update; +}; + +std::unique_ptr StickFromButton::Create(const Common::ParamPackage& params) { + const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); + auto up = Input::CreateDeviceFromString(params.Get("up", null_engine)); + auto down = Input::CreateDeviceFromString(params.Get("down", null_engine)); + auto left = Input::CreateDeviceFromString(params.Get("left", null_engine)); + auto right = + Input::CreateDeviceFromString(params.Get("right", null_engine)); + auto modifier = + Input::CreateDeviceFromString(params.Get("modifier", null_engine)); + auto modifier_scale = params.Get("modifier_scale", 0.5f); + auto modifier_angle = params.Get("modifier_angle", 5.5f); + return std::make_unique(std::move(up), std::move(down), std::move(left), + std::move(right), std::move(modifier), modifier_scale, + modifier_angle); +} + +} // namespace InputCommon diff --git a/src/input_common/helpers/stick_from_buttons.h b/src/input_common/helpers/stick_from_buttons.h new file mode 100644 index 000000000..1d6e24c98 --- /dev/null +++ b/src/input_common/helpers/stick_from_buttons.h @@ -0,0 +1,31 @@ + +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/input.h" + +namespace InputCommon { + +/** + * An analog device factory that takes direction button devices and combines them into a analog + * device. + */ +class StickFromButton final : public Input::Factory { +public: + /** + * Creates an analog device from direction button devices + * @param params contains parameters for creating the device: + * - "up": a serialized ParamPackage for creating a button device for up direction + * - "down": a serialized ParamPackage for creating a button device for down direction + * - "left": a serialized ParamPackage for creating a button device for left direction + * - "right": a serialized ParamPackage for creating a button device for right direction + * - "modifier": a serialized ParamPackage for creating a button device as the modifier + * - "modifier_scale": a float for the multiplier the modifier gives to the position + */ + std::unique_ptr Create(const Common::ParamPackage& params) override; +}; + +} // namespace InputCommon diff --git a/src/input_common/helpers/touch_from_buttons.cpp b/src/input_common/helpers/touch_from_buttons.cpp new file mode 100644 index 000000000..2abfaf841 --- /dev/null +++ b/src/input_common/helpers/touch_from_buttons.cpp @@ -0,0 +1,70 @@ +// Copyright 2020 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include "common/settings.h" +#include "core/frontend/framebuffer_layout.h" +#include "input_common/helpers/touch_from_buttons.h" + +namespace InputCommon { + +class TouchFromButtonDevice final : public Input::InputDevice { +public: + using Button = std::unique_ptr; + TouchFromButtonDevice(Button button_, u32 touch_id_, float x_, float y_) + : button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) { + Input::InputCallback button_up_callback{ + [this](Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }}; + button->SetCallback(button_up_callback); + } + + Input::TouchStatus GetStatus(bool pressed) const { + const Input::ButtonStatus button_status{ + .value = pressed, + }; + Input::TouchStatus status{ + .pressed = button_status, + .x = {}, + .y = {}, + .id = touch_id, + }; + status.x.properties = properties; + status.y.properties = properties; + + if (!pressed) { + return status; + } + + status.x.raw_value = x; + status.y.raw_value = y; + return status; + } + + void UpdateButtonStatus(Input::CallbackStatus button_callback) { + const Input::CallbackStatus status{ + .type = Input::InputType::Touch, + .touch_status = GetStatus(button_callback.button_status.value), + }; + TriggerOnChange(status); + } + +private: + Button button; + const u32 touch_id; + const float x; + const float y; + const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; +}; + +std::unique_ptr TouchFromButton::Create(const Common::ParamPackage& params) { + const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); + auto button = + Input::CreateDeviceFromString(params.Get("button", null_engine)); + const auto touch_id = params.Get("touch_id", 0); + const float x = params.Get("x", 0.0f) / 1280.0f; + const float y = params.Get("y", 0.0f) / 720.0f; + return std::make_unique(std::move(button), touch_id, x, y); +} + +} // namespace InputCommon diff --git a/src/input_common/helpers/touch_from_buttons.h b/src/input_common/helpers/touch_from_buttons.h new file mode 100644 index 000000000..21b353728 --- /dev/null +++ b/src/input_common/helpers/touch_from_buttons.h @@ -0,0 +1,22 @@ +// Copyright 2020 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/input.h" + +namespace InputCommon { + +/** + * A touch device factory that takes a list of button devices and combines them into a touch device. + */ +class TouchFromButton final : public Input::Factory { +public: + /** + * Creates a touch device from a list of button devices + */ + std::unique_ptr Create(const Common::ParamPackage& params) override; +}; + +} // namespace InputCommon diff --git a/src/input_common/helpers/udp_protocol.cpp b/src/input_common/helpers/udp_protocol.cpp new file mode 100644 index 000000000..cdeab7e11 --- /dev/null +++ b/src/input_common/helpers/udp_protocol.cpp @@ -0,0 +1,78 @@ +// Copyright 2018 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include "common/logging/log.h" +#include "input_common/helpers/udp_protocol.h" + +namespace InputCommon::CemuhookUDP { + +static constexpr std::size_t GetSizeOfResponseType(Type t) { + switch (t) { + case Type::Version: + return sizeof(Response::Version); + case Type::PortInfo: + return sizeof(Response::PortInfo); + case Type::PadData: + return sizeof(Response::PadData); + } + return 0; +} + +namespace Response { + +/** + * Returns Type if the packet is valid, else none + * + * Note: Modifies the buffer to zero out the crc (since thats the easiest way to check without + * copying the buffer) + */ +std::optional Validate(u8* data, std::size_t size) { + if (size < sizeof(Header)) { + return std::nullopt; + } + Header header{}; + std::memcpy(&header, data, sizeof(Header)); + if (header.magic != SERVER_MAGIC) { + LOG_ERROR(Input, "UDP Packet has an unexpected magic value"); + return std::nullopt; + } + if (header.protocol_version != PROTOCOL_VERSION) { + LOG_ERROR(Input, "UDP Packet protocol mismatch"); + return std::nullopt; + } + if (header.type < Type::Version || header.type > Type::PadData) { + LOG_ERROR(Input, "UDP Packet is an unknown type"); + return std::nullopt; + } + + // Packet size must equal sizeof(Header) + sizeof(Data) + // and also verify that the packet info mentions the correct size. Since the spec includes the + // type of the packet as part of the data, we need to include it in size calculations here + // ie: payload_length == sizeof(T) + sizeof(Type) + const std::size_t data_len = GetSizeOfResponseType(header.type); + if (header.payload_length != data_len + sizeof(Type) || size < data_len + sizeof(Header)) { + LOG_ERROR( + Input, + "UDP Packet payload length doesn't match. Received: {} PayloadLength: {} Expected: {}", + size, header.payload_length, data_len + sizeof(Type)); + return std::nullopt; + } + + const u32 crc32 = header.crc; + boost::crc_32_type result; + // zero out the crc in the buffer and then run the crc against it + std::memset(&data[offsetof(Header, crc)], 0, sizeof(u32_le)); + + result.process_bytes(data, data_len + sizeof(Header)); + if (crc32 != result.checksum()) { + LOG_ERROR(Input, "UDP Packet CRC check failed. Offset: {}", offsetof(Header, crc)); + return std::nullopt; + } + return header.type; +} +} // namespace Response + +} // namespace InputCommon::CemuhookUDP diff --git a/src/input_common/helpers/udp_protocol.h b/src/input_common/helpers/udp_protocol.h new file mode 100644 index 000000000..1bdc9209e --- /dev/null +++ b/src/input_common/helpers/udp_protocol.h @@ -0,0 +1,259 @@ +// Copyright 2018 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +#include + +#include "common/bit_field.h" +#include "common/swap.h" + +namespace InputCommon::CemuhookUDP { + +constexpr std::size_t MAX_PACKET_SIZE = 100; +constexpr u16 PROTOCOL_VERSION = 1001; +constexpr u32 CLIENT_MAGIC = 0x43555344; // DSUC (but flipped for LE) +constexpr u32 SERVER_MAGIC = 0x53555344; // DSUS (but flipped for LE) + +enum class Type : u32 { + Version = 0x00100000, + PortInfo = 0x00100001, + PadData = 0x00100002, +}; + +struct Header { + u32_le magic{}; + u16_le protocol_version{}; + u16_le payload_length{}; + u32_le crc{}; + u32_le id{}; + ///> In the protocol, the type of the packet is not part of the header, but its convenient to + ///> include in the header so the callee doesn't have to duplicate the type twice when building + ///> the data + Type type{}; +}; +static_assert(sizeof(Header) == 20, "UDP Message Header struct has wrong size"); +static_assert(std::is_trivially_copyable_v
, "UDP Message Header is not trivially copyable"); + +using MacAddress = std::array; +constexpr MacAddress EMPTY_MAC_ADDRESS = {0, 0, 0, 0, 0, 0}; + +#pragma pack(push, 1) +template +struct Message { + Header header{}; + T data; +}; +#pragma pack(pop) + +template +constexpr Type GetMessageType(); + +namespace Request { + +struct Version {}; +/** + * Requests the server to send information about what controllers are plugged into the ports + * In citra's case, we only have one controller, so for simplicity's sake, we can just send a + * request explicitly for the first controller port and leave it at that. In the future it would be + * nice to make this configurable + */ +constexpr u32 MAX_PORTS = 4; +struct PortInfo { + u32_le pad_count{}; ///> Number of ports to request data for + std::array port; +}; +static_assert(std::is_trivially_copyable_v, + "UDP Request PortInfo is not trivially copyable"); + +/** + * Request the latest pad information from the server. If the server hasn't received this message + * from the client in a reasonable time frame, the server will stop sending updates. The default + * timeout seems to be 5 seconds. + */ +struct PadData { + enum class Flags : u8 { + AllPorts, + Id, + Mac, + }; + /// Determines which method will be used as a look up for the controller + Flags flags{}; + /// Index of the port of the controller to retrieve data about + u8 port_id{}; + /// Mac address of the controller to retrieve data about + MacAddress mac; +}; +static_assert(sizeof(PadData) == 8, "UDP Request PadData struct has wrong size"); +static_assert(std::is_trivially_copyable_v, + "UDP Request PadData is not trivially copyable"); + +/** + * Creates a message with the proper header data that can be sent to the server. + * @param data Request body to send + * @param client_id ID of the udp client (usually not checked on the server) + */ +template +Message Create(const T data, const u32 client_id = 0) { + boost::crc_32_type crc; + Header header{ + CLIENT_MAGIC, PROTOCOL_VERSION, sizeof(T) + sizeof(Type), 0, client_id, GetMessageType(), + }; + Message message{header, data}; + crc.process_bytes(&message, sizeof(Message)); + message.header.crc = crc.checksum(); + return message; +} +} // namespace Request + +namespace Response { + +struct Version { + u16_le version{}; +}; +static_assert(sizeof(Version) == 2, "UDP Response Version struct has wrong size"); +static_assert(std::is_trivially_copyable_v, + "UDP Response Version is not trivially copyable"); + +struct PortInfo { + u8 id{}; + u8 state{}; + u8 model{}; + u8 connection_type{}; + MacAddress mac; + u8 battery{}; + u8 is_pad_active{}; +}; +static_assert(sizeof(PortInfo) == 12, "UDP Response PortInfo struct has wrong size"); +static_assert(std::is_trivially_copyable_v, + "UDP Response PortInfo is not trivially copyable"); + +struct TouchPad { + u8 is_active{}; + u8 id{}; + u16_le x{}; + u16_le y{}; +}; +static_assert(sizeof(TouchPad) == 6, "UDP Response TouchPad struct has wrong size "); + +#pragma pack(push, 1) +struct PadData { + PortInfo info{}; + u32_le packet_counter{}; + + u16_le digital_button{}; + // The following union isn't trivially copyable but we don't use this input anyway. + // union DigitalButton { + // u16_le button; + // BitField<0, 1, u16> button_1; // Share + // BitField<1, 1, u16> button_2; // L3 + // BitField<2, 1, u16> button_3; // R3 + // BitField<3, 1, u16> button_4; // Options + // BitField<4, 1, u16> button_5; // Up + // BitField<5, 1, u16> button_6; // Right + // BitField<6, 1, u16> button_7; // Down + // BitField<7, 1, u16> button_8; // Left + // BitField<8, 1, u16> button_9; // L2 + // BitField<9, 1, u16> button_10; // R2 + // BitField<10, 1, u16> button_11; // L1 + // BitField<11, 1, u16> button_12; // R1 + // BitField<12, 1, u16> button_13; // Triangle + // BitField<13, 1, u16> button_14; // Circle + // BitField<14, 1, u16> button_15; // Cross + // BitField<15, 1, u16> button_16; // Square + // } digital_button; + + u8 home; + /// If the device supports a "click" on the touchpad, this will change to 1 when a click happens + u8 touch_hard_press{}; + u8 left_stick_x{}; + u8 left_stick_y{}; + u8 right_stick_x{}; + u8 right_stick_y{}; + + struct AnalogButton { + u8 button_8{}; + u8 button_7{}; + u8 button_6{}; + u8 button_5{}; + u8 button_12{}; + u8 button_11{}; + u8 button_10{}; + u8 button_9{}; + u8 button_16{}; + u8 button_15{}; + u8 button_14{}; + u8 button_13{}; + } analog_button; + + std::array touch; + + u64_le motion_timestamp; + + struct Accelerometer { + float x{}; + float y{}; + float z{}; + } accel; + + struct Gyroscope { + float pitch{}; + float yaw{}; + float roll{}; + } gyro; +}; +#pragma pack(pop) + +static_assert(sizeof(PadData) == 80, "UDP Response PadData struct has wrong size "); +static_assert(std::is_trivially_copyable_v, + "UDP Response PadData is not trivially copyable"); + +static_assert(sizeof(Message) == MAX_PACKET_SIZE, + "UDP MAX_PACKET_SIZE is no longer larger than Message"); + +static_assert(sizeof(PadData::AnalogButton) == 12, + "UDP Response AnalogButton struct has wrong size "); +static_assert(sizeof(PadData::Accelerometer) == 12, + "UDP Response Accelerometer struct has wrong size "); +static_assert(sizeof(PadData::Gyroscope) == 12, "UDP Response Gyroscope struct has wrong size "); + +/** + * Create a Response Message from the data + * @param data array of bytes sent from the server + * @return boost::none if it failed to parse or Type if it succeeded. The client can then safely + * copy the data into the appropriate struct for that Type + */ +std::optional Validate(u8* data, std::size_t size); + +} // namespace Response + +template <> +constexpr Type GetMessageType() { + return Type::Version; +} +template <> +constexpr Type GetMessageType() { + return Type::PortInfo; +} +template <> +constexpr Type GetMessageType() { + return Type::PadData; +} +template <> +constexpr Type GetMessageType() { + return Type::Version; +} +template <> +constexpr Type GetMessageType() { + return Type::PortInfo; +} +template <> +constexpr Type GetMessageType() { + return Type::PadData; +} +} // namespace InputCommon::CemuhookUDP diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index f3907c65a..7a5c29b40 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -6,7 +6,6 @@ #include #include "common/param_package.h" #include "common/settings.h" -#include "input_common/analog_from_button.h" #include "input_common/gcadapter/gc_adapter.h" #include "input_common/gcadapter/gc_poller.h" #include "input_common/keyboard.h" @@ -16,7 +15,6 @@ #include "input_common/mouse/mouse_poller.h" #include "input_common/tas/tas_input.h" #include "input_common/tas/tas_poller.h" -#include "input_common/touch_from_button.h" #include "input_common/udp/client.h" #include "input_common/udp/udp.h" #ifdef HAVE_SDL2 @@ -37,12 +35,8 @@ struct InputSubsystem::Impl { keyboard = std::make_shared(); Input::RegisterFactory("keyboard", keyboard); - Input::RegisterFactory("analog_from_button", - std::make_shared()); Input::RegisterFactory("keyboard", std::make_shared()); - Input::RegisterFactory("touch_from_button", - std::make_shared()); #ifdef HAVE_SDL2 sdl = SDL::Init(); @@ -75,8 +69,6 @@ struct InputSubsystem::Impl { Input::UnregisterFactory("keyboard"); Input::UnregisterFactory("keyboard"); keyboard.reset(); - Input::UnregisterFactory("analog_from_button"); - Input::UnregisterFactory("touch_from_button"); #ifdef HAVE_SDL2 sdl.reset(); #endif diff --git a/src/input_common/touch_from_button.cpp b/src/input_common/touch_from_button.cpp deleted file mode 100644 index 7878a56d7..000000000 --- a/src/input_common/touch_from_button.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2020 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include -#include "common/settings.h" -#include "core/frontend/framebuffer_layout.h" -#include "input_common/touch_from_button.h" - -namespace InputCommon { - -class TouchFromButtonDevice final : public Input::TouchDevice { -public: - TouchFromButtonDevice() { - const auto button_index = - static_cast(Settings::values.touch_from_button_map_index.GetValue()); - const auto& buttons = Settings::values.touch_from_button_maps[button_index].buttons; - - for (const auto& config_entry : buttons) { - const Common::ParamPackage package{config_entry}; - map.emplace_back( - Input::CreateDevice(config_entry), - std::clamp(package.Get("x", 0), 0, static_cast(Layout::ScreenUndocked::Width)), - std::clamp(package.Get("y", 0), 0, - static_cast(Layout::ScreenUndocked::Height))); - } - } - - Input::TouchStatus GetStatus() const override { - Input::TouchStatus touch_status{}; - for (std::size_t id = 0; id < map.size() && id < touch_status.size(); ++id) { - const bool state = std::get<0>(map[id])->GetStatus(); - if (state) { - const float x = static_cast(std::get<1>(map[id])) / - static_cast(Layout::ScreenUndocked::Width); - const float y = static_cast(std::get<2>(map[id])) / - static_cast(Layout::ScreenUndocked::Height); - touch_status[id] = {x, y, true}; - } - } - return touch_status; - } - -private: - // A vector of the mapped button, its x and its y-coordinate - std::vector, int, int>> map; -}; - -std::unique_ptr TouchFromButtonFactory::Create(const Common::ParamPackage&) { - return std::make_unique(); -} - -} // namespace InputCommon diff --git a/src/input_common/touch_from_button.h b/src/input_common/touch_from_button.h deleted file mode 100644 index 8b4d1aa96..000000000 --- a/src/input_common/touch_from_button.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2020 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include -#include "core/frontend/input.h" - -namespace InputCommon { - -/** - * A touch device factory that takes a list of button devices and combines them into a touch device. - */ -class TouchFromButtonFactory final : public Input::Factory { -public: - /** - * Creates a touch device from a list of button devices - */ - std::unique_ptr Create(const Common::ParamPackage& params) override; -}; - -} // namespace InputCommon diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index b9512aa2e..bcc29c4e0 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -11,7 +11,7 @@ #include "common/logging/log.h" #include "common/settings.h" #include "input_common/udp/client.h" -#include "input_common/udp/protocol.h" +#include "input_common/helpers/udp_protocol.h" using boost::asio::ip::udp; diff --git a/src/input_common/udp/protocol.cpp b/src/input_common/udp/protocol.cpp deleted file mode 100644 index 5e50bd612..000000000 --- a/src/input_common/udp/protocol.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2018 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include -#include -#include "common/logging/log.h" -#include "input_common/udp/protocol.h" - -namespace InputCommon::CemuhookUDP { - -static constexpr std::size_t GetSizeOfResponseType(Type t) { - switch (t) { - case Type::Version: - return sizeof(Response::Version); - case Type::PortInfo: - return sizeof(Response::PortInfo); - case Type::PadData: - return sizeof(Response::PadData); - } - return 0; -} - -namespace Response { - -/** - * Returns Type if the packet is valid, else none - * - * Note: Modifies the buffer to zero out the crc (since thats the easiest way to check without - * copying the buffer) - */ -std::optional Validate(u8* data, std::size_t size) { - if (size < sizeof(Header)) { - return std::nullopt; - } - Header header{}; - std::memcpy(&header, data, sizeof(Header)); - if (header.magic != SERVER_MAGIC) { - LOG_ERROR(Input, "UDP Packet has an unexpected magic value"); - return std::nullopt; - } - if (header.protocol_version != PROTOCOL_VERSION) { - LOG_ERROR(Input, "UDP Packet protocol mismatch"); - return std::nullopt; - } - if (header.type < Type::Version || header.type > Type::PadData) { - LOG_ERROR(Input, "UDP Packet is an unknown type"); - return std::nullopt; - } - - // Packet size must equal sizeof(Header) + sizeof(Data) - // and also verify that the packet info mentions the correct size. Since the spec includes the - // type of the packet as part of the data, we need to include it in size calculations here - // ie: payload_length == sizeof(T) + sizeof(Type) - const std::size_t data_len = GetSizeOfResponseType(header.type); - if (header.payload_length != data_len + sizeof(Type) || size < data_len + sizeof(Header)) { - LOG_ERROR( - Input, - "UDP Packet payload length doesn't match. Received: {} PayloadLength: {} Expected: {}", - size, header.payload_length, data_len + sizeof(Type)); - return std::nullopt; - } - - const u32 crc32 = header.crc; - boost::crc_32_type result; - // zero out the crc in the buffer and then run the crc against it - std::memset(&data[offsetof(Header, crc)], 0, sizeof(u32_le)); - - result.process_bytes(data, data_len + sizeof(Header)); - if (crc32 != result.checksum()) { - LOG_ERROR(Input, "UDP Packet CRC check failed. Offset: {}", offsetof(Header, crc)); - return std::nullopt; - } - return header.type; -} -} // namespace Response - -} // namespace InputCommon::CemuhookUDP diff --git a/src/input_common/udp/protocol.h b/src/input_common/udp/protocol.h deleted file mode 100644 index 1bdc9209e..000000000 --- a/src/input_common/udp/protocol.h +++ /dev/null @@ -1,259 +0,0 @@ -// Copyright 2018 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include -#include -#include - -#include - -#include "common/bit_field.h" -#include "common/swap.h" - -namespace InputCommon::CemuhookUDP { - -constexpr std::size_t MAX_PACKET_SIZE = 100; -constexpr u16 PROTOCOL_VERSION = 1001; -constexpr u32 CLIENT_MAGIC = 0x43555344; // DSUC (but flipped for LE) -constexpr u32 SERVER_MAGIC = 0x53555344; // DSUS (but flipped for LE) - -enum class Type : u32 { - Version = 0x00100000, - PortInfo = 0x00100001, - PadData = 0x00100002, -}; - -struct Header { - u32_le magic{}; - u16_le protocol_version{}; - u16_le payload_length{}; - u32_le crc{}; - u32_le id{}; - ///> In the protocol, the type of the packet is not part of the header, but its convenient to - ///> include in the header so the callee doesn't have to duplicate the type twice when building - ///> the data - Type type{}; -}; -static_assert(sizeof(Header) == 20, "UDP Message Header struct has wrong size"); -static_assert(std::is_trivially_copyable_v
, "UDP Message Header is not trivially copyable"); - -using MacAddress = std::array; -constexpr MacAddress EMPTY_MAC_ADDRESS = {0, 0, 0, 0, 0, 0}; - -#pragma pack(push, 1) -template -struct Message { - Header header{}; - T data; -}; -#pragma pack(pop) - -template -constexpr Type GetMessageType(); - -namespace Request { - -struct Version {}; -/** - * Requests the server to send information about what controllers are plugged into the ports - * In citra's case, we only have one controller, so for simplicity's sake, we can just send a - * request explicitly for the first controller port and leave it at that. In the future it would be - * nice to make this configurable - */ -constexpr u32 MAX_PORTS = 4; -struct PortInfo { - u32_le pad_count{}; ///> Number of ports to request data for - std::array port; -}; -static_assert(std::is_trivially_copyable_v, - "UDP Request PortInfo is not trivially copyable"); - -/** - * Request the latest pad information from the server. If the server hasn't received this message - * from the client in a reasonable time frame, the server will stop sending updates. The default - * timeout seems to be 5 seconds. - */ -struct PadData { - enum class Flags : u8 { - AllPorts, - Id, - Mac, - }; - /// Determines which method will be used as a look up for the controller - Flags flags{}; - /// Index of the port of the controller to retrieve data about - u8 port_id{}; - /// Mac address of the controller to retrieve data about - MacAddress mac; -}; -static_assert(sizeof(PadData) == 8, "UDP Request PadData struct has wrong size"); -static_assert(std::is_trivially_copyable_v, - "UDP Request PadData is not trivially copyable"); - -/** - * Creates a message with the proper header data that can be sent to the server. - * @param data Request body to send - * @param client_id ID of the udp client (usually not checked on the server) - */ -template -Message Create(const T data, const u32 client_id = 0) { - boost::crc_32_type crc; - Header header{ - CLIENT_MAGIC, PROTOCOL_VERSION, sizeof(T) + sizeof(Type), 0, client_id, GetMessageType(), - }; - Message message{header, data}; - crc.process_bytes(&message, sizeof(Message)); - message.header.crc = crc.checksum(); - return message; -} -} // namespace Request - -namespace Response { - -struct Version { - u16_le version{}; -}; -static_assert(sizeof(Version) == 2, "UDP Response Version struct has wrong size"); -static_assert(std::is_trivially_copyable_v, - "UDP Response Version is not trivially copyable"); - -struct PortInfo { - u8 id{}; - u8 state{}; - u8 model{}; - u8 connection_type{}; - MacAddress mac; - u8 battery{}; - u8 is_pad_active{}; -}; -static_assert(sizeof(PortInfo) == 12, "UDP Response PortInfo struct has wrong size"); -static_assert(std::is_trivially_copyable_v, - "UDP Response PortInfo is not trivially copyable"); - -struct TouchPad { - u8 is_active{}; - u8 id{}; - u16_le x{}; - u16_le y{}; -}; -static_assert(sizeof(TouchPad) == 6, "UDP Response TouchPad struct has wrong size "); - -#pragma pack(push, 1) -struct PadData { - PortInfo info{}; - u32_le packet_counter{}; - - u16_le digital_button{}; - // The following union isn't trivially copyable but we don't use this input anyway. - // union DigitalButton { - // u16_le button; - // BitField<0, 1, u16> button_1; // Share - // BitField<1, 1, u16> button_2; // L3 - // BitField<2, 1, u16> button_3; // R3 - // BitField<3, 1, u16> button_4; // Options - // BitField<4, 1, u16> button_5; // Up - // BitField<5, 1, u16> button_6; // Right - // BitField<6, 1, u16> button_7; // Down - // BitField<7, 1, u16> button_8; // Left - // BitField<8, 1, u16> button_9; // L2 - // BitField<9, 1, u16> button_10; // R2 - // BitField<10, 1, u16> button_11; // L1 - // BitField<11, 1, u16> button_12; // R1 - // BitField<12, 1, u16> button_13; // Triangle - // BitField<13, 1, u16> button_14; // Circle - // BitField<14, 1, u16> button_15; // Cross - // BitField<15, 1, u16> button_16; // Square - // } digital_button; - - u8 home; - /// If the device supports a "click" on the touchpad, this will change to 1 when a click happens - u8 touch_hard_press{}; - u8 left_stick_x{}; - u8 left_stick_y{}; - u8 right_stick_x{}; - u8 right_stick_y{}; - - struct AnalogButton { - u8 button_8{}; - u8 button_7{}; - u8 button_6{}; - u8 button_5{}; - u8 button_12{}; - u8 button_11{}; - u8 button_10{}; - u8 button_9{}; - u8 button_16{}; - u8 button_15{}; - u8 button_14{}; - u8 button_13{}; - } analog_button; - - std::array touch; - - u64_le motion_timestamp; - - struct Accelerometer { - float x{}; - float y{}; - float z{}; - } accel; - - struct Gyroscope { - float pitch{}; - float yaw{}; - float roll{}; - } gyro; -}; -#pragma pack(pop) - -static_assert(sizeof(PadData) == 80, "UDP Response PadData struct has wrong size "); -static_assert(std::is_trivially_copyable_v, - "UDP Response PadData is not trivially copyable"); - -static_assert(sizeof(Message) == MAX_PACKET_SIZE, - "UDP MAX_PACKET_SIZE is no longer larger than Message"); - -static_assert(sizeof(PadData::AnalogButton) == 12, - "UDP Response AnalogButton struct has wrong size "); -static_assert(sizeof(PadData::Accelerometer) == 12, - "UDP Response Accelerometer struct has wrong size "); -static_assert(sizeof(PadData::Gyroscope) == 12, "UDP Response Gyroscope struct has wrong size "); - -/** - * Create a Response Message from the data - * @param data array of bytes sent from the server - * @return boost::none if it failed to parse or Type if it succeeded. The client can then safely - * copy the data into the appropriate struct for that Type - */ -std::optional Validate(u8* data, std::size_t size); - -} // namespace Response - -template <> -constexpr Type GetMessageType() { - return Type::Version; -} -template <> -constexpr Type GetMessageType() { - return Type::PortInfo; -} -template <> -constexpr Type GetMessageType() { - return Type::PadData; -} -template <> -constexpr Type GetMessageType() { - return Type::Version; -} -template <> -constexpr Type GetMessageType() { - return Type::PortInfo; -} -template <> -constexpr Type GetMessageType() { - return Type::PadData; -} -} // namespace InputCommon::CemuhookUDP -- cgit v1.2.3