Git Product home page Git Product logo

Comments (12)

TheDrHax avatar TheDrHax commented on August 19, 2024 1

Current implementation of UDP server only supports one controller at a time. The driver, in theory, does support multiple controllers, but I do not have the second one to test this.

from ds4drv-cemuhook.

TheDrHax avatar TheDrHax commented on August 19, 2024 1

Oh, this TODO is exactly what we need:

def _req_data(self, message, address):
flags = self._compat_ord(message[24])
reg_id = self._compat_ord(message[25])
# reg_mac = message[26:32]
if flags == 0 and reg_id == 0: # TODO: Check MAC
if address not in self.clients:
print('[udp] Client connected: {0[0]}:{0[1]}'.format(address))

The protocol supports two different modes for registration: slot-based and MAC-based.

from ds4drv-cemuhook.

TheDrHax avatar TheDrHax commented on August 19, 2024 1

I pushed another change to the same branch. It works with Dolphin now (at least on my side) :)

from ds4drv-cemuhook.

ee5cd7d5d avatar ee5cd7d5d commented on August 19, 2024

I could actually try to implement it myself when I have time :) could you give me a rough idea of what I would need to do in order to achieve that? Like how would I need to change the UDP packet...

from ds4drv-cemuhook.

TheDrHax avatar TheDrHax commented on August 19, 2024
  1. Right now UDP server is being started inside controller's thread, so when there are two controllers, there will be two servers. We probably need to initialize a single UDP server instance before any controllers are registered in __main__.py instead of doing it in input.py;

if options.udp and not self.server:
self.server = UDPServer(options.udp_host, options.udp_port)
self.server.remap = options.udp_remap_buttons
self.server.send_touch = not options.udp_no_touch
self.server.start()

for index, controller_options in enumerate(options.controllers):
thread = create_controller_thread(index + 1, controller_options)
threads.append(thread)

  1. For client to be able to detect multiple controllers, we need to send multiple packets from UDPServer._req_ports. This part is almost ready, we just need to keep count of active controllers and populate responses with real data (MAC address);

def _req_ports(self, message, address):
requests_count = struct.unpack("<i", message[20:24])[0]
for i in range(requests_count):
index = self._compat_ord(message[24 + i])
if (index != 0): # we have only one controller
continue
self.sock.sendto(bytes(self._res_ports(index)), address)

  1. In UDPServer.report "pad id" field will depend on the source of the report. Right now it is hard coded to 0 (first controller);

def report(self, report):
if len(self.clients) == 0:
return None
data = [
0x00, # pad id
0x02, # state (connected)

  1. To read input events from each controller we can probably use DS4Controller.loop.register_event("device-report", callback) instead of modifying ReportActionInput.handle_report.

def handle_report(self, report):
if self.server:
self.server.report(report)

I will try to make it work with a single controller. Probably it will then start working with multiple controllers as well :)

from ds4drv-cemuhook.

TheDrHax avatar TheDrHax commented on August 19, 2024

I've created a separate branch for this feature. Could you please test it?

  • pip3 install git+https://github.com/TheDrHax/ds4drv-cemuhook.git@multiple-controllers
  • ds4drv --hidraw --udp --next-controller

from ds4drv-cemuhook.

ee5cd7d5d avatar ee5cd7d5d commented on August 19, 2024

Hi! It's working better now, at least there is data from both controllers, but it seems to be mixing up the packets. Now Dolphin is detecting both controllers but it's showing the sensors from both in both, switching very rapidly between the values of each controller (like several times per second)

Padtest + wine seems to not have the problem, but I think it is filtering the packets clientside using the MAC Address

from ds4drv-cemuhook.

TheDrHax avatar TheDrHax commented on August 19, 2024

I was able to reproduce this issue with a single controller by copying reports to another slot and changing them slightly.

Apparently, Dolphin creates a separate connection for each controller, ignores pad id byte and expects only updates for a single controller per connection. So the server needs to keep track of each client's requests.

from ds4drv-cemuhook.

ee5cd7d5d avatar ee5cd7d5d commented on August 19, 2024

I checked with a newer build of dolphin to see if it improved, but the problem remains. I will not get to look into it right away, but let me know if I can do anything to help 😊

from ds4drv-cemuhook.

ee5cd7d5d avatar ee5cd7d5d commented on August 19, 2024

Yes! It works! Thank you so much!

from ds4drv-cemuhook.

TheDrHax avatar TheDrHax commented on August 19, 2024

Nice! I will merge it with master now 👍

from ds4drv-cemuhook.

oblitum avatar oblitum commented on August 19, 2024

This seems to not have fixed on cemu's side.. I can only get one game pad motion source (DSU1) listed in options, all others show as disconnected, despite the ds4drv logs showing two controllers got connected.

from ds4drv-cemuhook.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.