From e1ae14d5087e26d251ca74286cc0e14bcf798791 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Fri, 10 Aug 2018 14:15:26 +0800 Subject: [PATCH] input_common/udp: allow changing pad index --- src/citra/default_ini.h | 3 +++ src/citra_qt/configuration/config.cpp | 2 ++ src/core/settings.h | 1 + src/input_common/udp/client.cpp | 20 +++++++++++--------- src/input_common/udp/client.h | 2 +- src/input_common/udp/udp.cpp | 5 +++-- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h index f0d5e3c15..756d3c68b 100644 --- a/src/citra/default_ini.h +++ b/src/citra/default_ini.h @@ -81,6 +81,9 @@ udp_input_address= # Port of the udp input server. (Default 26760) udp_input_port= +# The pad to request data on. Should be between 0 (Pad 1) and 3 (Pad 4). (Default 0) +udp_pad_index= + [Core] # Whether to use the Just-In-Time (JIT) compiler for CPU emulation # 0: Interpreter (slow), 1 (default): JIT (fast) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 2ae3e95fe..3aecc0942 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -81,6 +81,7 @@ void Config::ReadValues() { .toStdString(); Settings::values.udp_input_port = static_cast( ReadSetting("udp_input_port", InputCommon::CemuhookUDP::DEFAULT_PORT).toInt()); + Settings::values.udp_pad_index = static_cast(ReadSetting("udp_pad_index", 0).toUInt()); qt_config->endGroup(); @@ -331,6 +332,7 @@ void Config::SaveValues() { InputCommon::CemuhookUDP::DEFAULT_ADDR); WriteSetting("udp_input_port", Settings::values.udp_input_port, InputCommon::CemuhookUDP::DEFAULT_PORT); + WriteSetting("udp_pad_index", Settings::values.udp_pad_index, 0); qt_config->endGroup(); qt_config->beginGroup("Core"); diff --git a/src/core/settings.h b/src/core/settings.h index 980a41109..762246c33 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -98,6 +98,7 @@ struct Values { std::string touch_device; std::string udp_input_address; u16 udp_input_port; + u8 udp_pad_index; // Core bool use_cpu_jit; diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index a5343384c..9f668d233 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -30,10 +30,12 @@ class Socket { public: using clock = std::chrono::system_clock; - explicit Socket(const std::string& host, u16 port, u32 client_id, SocketCallback callback) + explicit Socket(const std::string& host, u16 port, u8 pad_index, u32 client_id, + SocketCallback callback) : client_id(client_id), timer(io_service), send_endpoint(udp::endpoint(address_v4::from_string(host), port)), - socket(io_service, udp::endpoint(udp::v4(), 0)), callback(std::move(callback)) {} + socket(io_service, udp::endpoint(udp::v4(), 0)), pad_index(pad_index), + callback(std::move(callback)) {} void Stop() { io_service.stop(); @@ -85,15 +87,14 @@ private: } void HandleSend(const boost::system::error_code& error) { - // TODO: add something to the UI to let people choose what ports to listen on - // Send a request for getting port info for pad 1 - Request::PortInfo port_info{1, {0, 0, 0, 0}}; + // Send a request for getting port info for the pad + Request::PortInfo port_info{1, {pad_index, 0, 0, 0}}; auto port_message = Request::Create(port_info, client_id); std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE); size_t len = socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint); - // Send a request for getting pad data for pad 1 - Request::PadData pad_data{Request::PadData::Flags::Id, 0, EMPTY_MAC_ADDRESS}; + // Send a request for getting pad data for the pad + Request::PadData pad_data{Request::PadData::Flags::Id, pad_index, EMPTY_MAC_ADDRESS}; auto pad_message = Request::Create(pad_data, client_id); std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE); size_t len2 = socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint); @@ -106,6 +107,7 @@ private: udp::socket socket; u32 client_id; + u8 pad_index; static constexpr size_t PORT_INFO_SIZE = sizeof(Message); static constexpr size_t PAD_DATA_SIZE = sizeof(Message); @@ -124,13 +126,13 @@ static void SocketLoop(Socket* socket) { } Client::Client(std::shared_ptr status, const std::string& host, u16 port, - u32 client_id) + u8 pad_index, u32 client_id) : status(status) { SocketCallback callback{[this](Response::Version version) { OnVersion(version); }, [this](Response::PortInfo info) { OnPortInfo(info); }, [this](Response::PadData data) { OnPadData(data); }}; LOG_INFO(Input, "Starting communication with UDP input server on {}:{}", host, port); - socket = std::make_unique(host, port, client_id, callback); + socket = std::make_unique(host, port, pad_index, client_id, callback); thread = std::thread{SocketLoop, this->socket.get()}; } diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index 633c7b41a..0dca3b28a 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h @@ -45,7 +45,7 @@ struct DeviceStatus { class Client { public: explicit Client(std::shared_ptr status, const std::string& host = DEFAULT_ADDR, - u16 port = DEFAULT_PORT, u32 client_id = 24872); + u16 port = DEFAULT_PORT, u8 pad_index = 0, u32 client_id = 24872); ~Client(); private: diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index 02af961b9..9e32d9fd9 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp @@ -70,8 +70,9 @@ private: State::State() { auto status = std::make_shared(); - client = std::make_unique(status, Settings::values.udp_input_address, - Settings::values.udp_input_port); + client = + std::make_unique(status, Settings::values.udp_input_address, + Settings::values.udp_input_port, Settings::values.udp_pad_index); Input::RegisterFactory("cemuhookudp", std::make_shared(status));