71 / stadiacontroller

Command line application that emulates an Xbox 360 controller from a wired Stadia controller on Windows.
ISC License
171 stars 22 forks source link

Unknown report format error #1

Closed bakapear closed 3 years ago

bakapear commented 3 years ago

The console is spammed with unable to parse controller report: unknown report format if I press any button on my stadia controller.

71 commented 3 years ago

Unfortunately it looks like the Stadia controller has a new firmware that sends different reports than before. I'll need to update my controller and then the code. Sorry but it might take a while.

Update: according to MWisBest's research, the format is the same as before but with more bytes appended. I'm pushing a version that accepts longer reports and parses them as before, and additionally prints unsupported reports as base64 for easier debugging if more problems come up.

71 commented 3 years ago

Release v1.1.0 should fix it. Please take a look.

bakapear commented 3 years ago

Thanks for looking into this issue so quickly!

I tried it and the unsupported reports are showing up for each key:

2020/10/20 12:09:04 unable to parse controller report: unknown report format; raw report was AwAAAICAgIAA
2020/10/20 12:09:04 unable to parse controller report: unknown report format; raw report was AwgAAICAgIAA
2020/10/20 12:09:05 unable to parse controller report: unknown report format; raw report was AwQAAICAgIAA
2020/10/20 12:09:05 unable to parse controller report: unknown report format; raw report was AwgAAICAgIAA
2020/10/20 12:09:06 unable to parse controller report: unknown report format; raw report was AwYAAICAgIAA
2020/10/20 12:09:06 unable to parse controller report: unknown report format; raw report was AwgAAICAgIAA
2020/10/20 12:09:06 unable to parse controller report: unknown report format; raw report was AwIAAICAgIAA
2020/10/20 12:09:06 unable to parse controller report: unknown report format; raw report was AwgAAICAgIAA
bakapear commented 3 years ago

I managed to fix the issue by changing line 384 in hid.go to this:

case d.readCh <- buf[:int(n)]:
// was int(n-1) before

My experience with the go language and hid devices is very minimal though and I cannot gurantee if this solution breaks other things.

71 commented 3 years ago

Ah, interesting! I'd be curious to see how you managed to find this (and to know why things seem to be different only for you).

Thanks for the fix, I'll add it to the repo.

bakapear commented 3 years ago

Well since I was getting the "unable to parse" error, that meant that this if condition turned out to be false: https://github.com/71/stadiacontroller/blob/48534c3c885b6675801059f95e703778f999414e/stadia.go#L115 So I printed the output of data before the condition to see why.
It turned out that the data length was 9.

Because of this I wanted to check which data input I was missing and removed the if condition for now. That left me with the error data[9] ~ index out of range (which makes sense because of the data length). Commented that line out and the controller worked - except for the Right Trigger.

report.SetLeftTrigger(data[8])
// report.SetRightTrigger(data[9])

Knowing that the data returned is accurate but missing it's last piece, I looked at the function that provided the data in the first place: https://github.com/71/stadiacontroller/blob/48534c3c885b6675801059f95e703778f999414e/stadia.go#L89 And checked if there was anything related to data length - 1. All I could find was the n-1 here: https://github.com/71/stadiacontroller/blob/48534c3c885b6675801059f95e703778f999414e/hid.go#L384 I do not know why exactly -1 was applied to n on this line, but after changing it to just n the issue was resolved!