rlabrecque / Steamworks.NET

Steamworks wrapper for Unity / C#
http://steamworks.github.io
MIT License
2.72k stars 361 forks source link

Steam hijacking controller input #380

Open Arcalise08 opened 3 years ago

Arcalise08 commented 3 years ago

Not sure if this intended or not. But upon initializing steamworks. My xbox one controller is no longer recognized within unity. No inputs will reach it until i close steam. I can get the game working by building it, opening the overlay and going to controller configurations then selecting to apply the generic gamepad. It will then work as intended. But within the editor nothing i do seems to work.

streaman commented 3 years ago

Same exact problem here. This is definitely BLOCKING and should be assigned and fixed asap.

Happens with Unity's New Input System.

Easy way to check the issue is running this code in an Update() callback:

    for (int i = 0; i < Gamepad.current.allControls.Count; i++) {
      InputControl ic = Gamepad.current.allControls[i];
      if (typeof(float).IsAssignableFrom(ic.valueType)) {
        float v = (float) ic.ReadValueAsObject();
        if (v > 0) {
          Debug.LogError("  [" + i + "]: " + ic.shortDisplayName + " = " + v);
        }
      }
    }

Before initializing Steamworks, this code will output a line to Unity console for every button or trigger pressed. After initializing Steamworks, all inputs will be 0 and nothing will be output to Unity console anymore. Only way to resume normal gamepad operation is quit&restart Unity and avoid initializing Steamworks.

Arcalise08 commented 3 years ago

Same exact problem here. This is definitely BLOCKING and should be assigned and fixed asap.

Happens with both Unity's Old and New Input System.

Easy way to check the issue is running this code in an Update() callback:

    for (int i = 0; i < Gamepad.current.allControls.Count; i++) {
      InputControl ic = Gamepad.current.allControls[i];
      if (typeof(float).IsAssignableFrom(ic.valueType)) {
        float v = (float) ic.ReadValueAsObject();
        if (v > 0) {
          Debug.LogError("  [" + i + "]: " + ic.shortDisplayName + " = " + v);
        }
      }
    }

Before initializing Steamworks, this code will output a line to Unity console for every button or trigger pressed. After initializing Steamworks, all inputs will be 0 and nothing will be output to Unity console anymore. Only way to resume normal gamepad operation is quit&restart Unity and avoid initializing Steamworks.

I've been messing around with it personally, And i dont actually think this is a steamworks.net issue. I think that engaging steam redirects input. Its just a fundamental compatibility issue with steam and unity. From my test, Actually building to steam servers and playing works just fine. Its just the quirk of testing controller inputs with steam initialized which is difficult. If anyone has a better solution, Or maybe i'm completely wrong about it being a steam issue and not a steamworks. Please let us know!

streaman commented 3 years ago

I agree this can be a Steamworks SDK issue, and not the .NET wrapper. It could also be a Unity bug (I filed a bug report with Unity too). Hope someone can tell us what's happening.

Arcalise08 commented 3 years ago

I agree this can be a Steamworks SDK issue, and not the .NET wrapper. It could also be a Unity bug (I filed a bug report with Unity too). Hope someone can tell us what's happening.

I've mostly fixed this issue. I'm not entirely sure how i did it. Try adding unity, the actual executable(not the hub) to steam and start unity through steam.

Again i do believe this to be a pretty bad bug. But at this point i have no idea how to replicate it nor do i want to.

streaman commented 3 years ago

Thanks for the feedback. I am afraid to use your workaround, as I want to be sure the game works regardless of the way the executable is started. By the way, a standalone build has the same issue, so it's not only the editor.

I double-checked the Old Input System, and it now seems to be working for me. For example, I can read the controller buttons using:

Input.GetKey(KeyCode.JoystickButton0)

It now looks more and more like a Unity bug to me. And it's so disappointing to realize that the New Input System (v1.0.0) is not being tested against one of the most obvious use cases (Steam games).

Arcalise08 commented 3 years ago

Thanks for the feedback. I am afraid to use your workaround, as I want to be sure the game works regardless of the way the executable is started. By the way, a standalone build has the same issue, so it's not only the editor.

Thats a little confusing. If your game is a steam game. You want it to launch with steam. When its built and distributed through steam. Steamworks will automatically close and relaunch your game through steam if it was started without steam. It doesnt do this if you have your app_id in the root folder such as when your developing. But otherwise it does. If its started without steam you wont be able to use steam features.

It now looks more and more like a Unity bug to me. And it's so disappointing to realize that the New Input System (v1.0.0) is > not being tested against one of the most obvious use cases (Steam games).

When i started targeting steam as my release partner i was absolutely shocked that steam doesnt officially support unity. Make no mistake though. This is on steams end, not unitys. Since steam is the distributor of the games, They are the ones whose responsibility it is to release plugins that support their distribution platform. Its my guess that they dont support unity because unity targets C# programmers while steamworks uses C++. Because they do officially support unreal engine.

Until they officially support unity, we have to deal with annoyances like this.

rlabrecque commented 3 years ago

https://steamcommunity.com/groups/SteamClientBeta/announcements/detail/2936869850608535686

Improved support for games using Windows raw input APIs Unity games using the Rewired plugin should upgrade to the latest release, version 1.1.36.1.

Did this Steam update improve things at all?

streaman commented 3 years ago

Hi Riley,

Thanks for the update. Unfortunately, this update has the same problem. I am attaching the source Script to replicate this bug (be sure the New Input System is enabled in Unity).

I contacted Unity, and they said they know about this bug and are tracking it here: https://issuetracker.unity3d.com/product/unity/issues/guid/1280203

Keep on the good work. Best, .dan

On Thu, Oct 22, 2020 at 1:18 PM Riley Labrecque notifications@github.com wrote:

https://steamcommunity.com/groups/SteamClientBeta/announcements/detail/2936869850608535686

Improved support for games using Windows raw input APIs Unity games using the Rewired plugin should upgrade to the latest release, version 1.1.36.1.

Did this Steam update improve things at all?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rlabrecque/Steamworks.NET/issues/380#issuecomment-714737130, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEMCN5EBZRWUK4COJTDV6ITSMCHQFANCNFSM4SCDKWKQ .

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; using Steamworks; using UnityEngine.InputSystem.Users; using System;

public class ReproduceBug : MonoBehaviour {

public bool ENABLE_STEAM = false; GameObject go_steam;

public InputActions input_; public InputUser inputuser;

// Start is called before the first frame update void Start() { Debug.LogError("Found " + Gamepad.all.Count + " controllers."); setup_InputSystem(); Debug.LogError("Press START on the controller to verify that the action is working."); }

// Update is called once per frame void Update() { // Print how manu controllers we have found.

if (ENABLE_STEAM) {
  if (go_steam == null) go_steam = new GameObject("Steam");
  SteamManager sm = go_steam.GetComponent<SteamManager>();
  if (sm == null) {
    Debug.LogError("ENABLING STEAM NOW");
    sm = go_steam.AddComponent<SteamManager>();
    if (SteamManager.Initialized) {
      Debug.LogError("Found " + Gamepad.all.Count + " controllers.");
      Debug.LogError("Press START on the controller. If the bug is present, you won't get any confirmation message from the callback anymore (you need to restart Unity).");
    }
    else {
      Debug.LogError("FAILED TO INITIALIZE SteamManager");
    }
  }
}

//Debug.LogError("Gamepad status: ");
for (int i = 0; i < Gamepad.current.allControls.Count; i++) {
  InputControl ic = Gamepad.current.allControls[i];
  if (typeof(float).IsAssignableFrom(ic.valueType)) {
    float v = (float) ic.ReadValueAsObject();
    if (v > 0) {
      Debug.LogError("  [" + i + "]: " + ic.shortDisplayName + " = " + v);
    }
  }
}

}

void steam_OnGetAuthSessionTicketResponse(GetAuthSessionTicketResponse_t pCallback) { //if (pCallback.m_eResult == EResult.k_EResultOK) { Debug.LogError("Steam authentication result: " + pCallback.m_eResult); //} Debug.LogError("Found " + Gamepad.all.Count + " controllers."); }

void setupInputSystem() { Debug.LogError("Setting up New Input System..."); input = new InputActions(); int player_num = 0; if (Gamepad.all.Count > player_num) { inputuser = InputUser.PerformPairingWithDevice(Gamepad.all[player_num]); inputuser.AssociateActionsWithUser(input_); inputuser.ActivateControlScheme("Default"); }

input_.Gameplay.Start.performed += ctx => { Debug.LogError("PRESSED: Start"); Debug.LogError("Now enable Steam using this script's boolean property \"ENABLE STEAM\"."); };

input_.Gameplay.Enable();
Debug.LogError("New Input System callback enabled.");

}

}

timkeo commented 3 years ago

Hey,

I'm a Unity software engineer and currently investigating this issue (Unity bug link).

From my investigation, the problem seems to be Steam itself is (for lack of a better word) "hijacking" XInput. Unity's internal calls to XInputGetState() fail with ERROR_DEVICE_NOT_CONNECTED once the Steam API is initialized. I suspect it's actually the Steam Overlay that may be causing the problem as I found we stop getting input once this DLL is loaded.

'Unity.exe' (Win32): Loaded 'C:\Program Files (x86)\Steam\GameOverlayRenderer64.dll'.

Since it's the Windows API itself that's failing, I don't think there's anything Unity nor Steamworks can do about it, However, I'd like to find a confirmed work around which I can paste into the bugs resolution notes.

Arcalise08 commented 3 years ago

Hey,

I'm a Unity software engineer and currently investigating this issue (Unity bug link).

From my investigation, the problem seems to be Steam itself is (for lack of a better word) "hijacking" XInput. Unity's internal calls to XInputGetState() fail with ERROR_DEVICE_NOT_CONNECTED once the Steam API is initialized. I suspect it's actually the Steam Overlay that may be causing the problem as I found we stop getting input once this DLL is loaded.

'Unity.exe' (Win32): Loaded 'C:\Program Files (x86)\Steam\GameOverlayRenderer64.dll'.

Since it's the Windows API itself that's failing, I don't think there's anything Unity nor Steamworks can do about it, However, I'd like to find a confirmed work around which I can paste into the bugs resolution notes.

From my test the inputs arent reaching unity and its not unity's fault for that. I found two ways of getting it working. You have to be able to open the Overlay in the editor. If you can do that, You can set the gamepad within the overlay and then it will work normally.

What is really strange is when you do get that overlay open. all you need to do is set the gamepad, The default gamepad works just fine but you still have to set it to something else. after you set it to something else you can then set it right back to default and it works. That means its default gamepad profile works just fine. Its just a matter of resetting it every time the game is started

I've mostly stopped messing with steam for the time being. But my trail of thinking was, If we programmatically unset the default controller profile then set it right back, It might work without needing the overlay.

You can also add unity to Steam as an external program. It will inject the overlay into unity and that works.. sometimes.. Its not dependable at all. so I wouldn't suggest that being a workaround.

timkeo commented 3 years ago

Thank you for the reply, I'll add this information to the Unity bug.

As I've dug deeper into this problem I've discovered...Steam iterally is hijacking XInput! When the Steam Overlay module is loaded, it actually modifies the XInput API call to redirect it to it's own code; basically what a virus would do.

From Unity we call into XInputGetState() which looks like this in the disassembly:

           errorCode = s_XInputGetStateFn(userIndex, &state);
00007FF78DDFAD4C  mov         rax,qword ptr [win::XInputDevice::s_XInputGetStateFn (07FF79E320148h)]  
00007FF78DDFAD53  mov         qword ptr [rsp+88h],rax  
00007FF78DDFAD5B  lea         rdx,[state]  
00007FF78DDFAD60  mov         rax,qword ptr [this]  
00007FF78DDFAD68  mov         ecx,dword ptr [rax+8]  
00007FF78DDFAD6B  call        qword ptr [rsp+88h]  => 00007FFF40B816F0 (XInput DLL address)
...

From here the disassembly (should) look like this:

XInputGetState:
00007FFF40B816F0  mov         qword ptr [rsp+8],rbx  
00007FFF40B816F5  push        rsi  
00007FFF40B816F6  push        rdi  
00007FFF40B816F7  push        r14  
00007FFF40B816F9  sub         rsp,30h
...  

Now, start Steamworks in the Editor and break into XInputGetState again:

XInputGetState:
00007FFF40B816F0  jmp         00007FFF62590E4A  
00007FFF40B816F5  push        rsi  
00007FFF40B816F6  push        rdi  
00007FFF40B816F7  push        r14  
00007FFF40B816F9  sub         rsp,30h  
...

Notice the mov instruction from before has been replaced by a jmp

That jump takes us to some other place in memory where we encounter these 2 instructions:

00007FFF62590E45  jmp         XInputGetState+5h (07FFF40B816F5h)  
00007FFF62590E4A  jmp         00007FFEFA7F0790  

The 1st jmp instruction, which we do not execute, takes us back to XInputGetState, and continues to execute the API normally. The 2nd jmp instruction, which we end up calling, takes us here:

00007FFEFA7F0790  mov         r8,rdx  
00007FFEFA7F0793  xor         r9d,r9d  
00007FFEFA7F0796  mov         edx,ecx  
00007FFEFA7F0798  mov         rcx,qword ptr [7FFEFA8EE1D8h]  
00007FFEFA7F079F  jmp         00007FFEFA7F07D0  
...

Using the module info, this instruction address occurs within Steam's GameOverlay: (Module) GameOverlayRenderer64.dll (Addr Range) 00007FFEFA730000-00007FFEFA911000

I'm unsure exactly what this Steam function is doing but it ultimately dumps out the error code for ERROR_DEVICE_NOT_CONNECTED before returning.

So basically Steam is deliberately overriding XInput to block input for other callers (in the same process) once the Overlay DLL has been loaded unless you do something special.

Based on the comment above, my guess is Steam redirects the XInput API call depending on the state of things. If you do the "right" thing it injects the jmp instruction to point to the 1st address (00007FFF62590E45 in this case) and everything works fine, but if you don't do the magic thingy you get the 2nd address (00007FFF62590E4A, what we're currently seeing) and Input no longer works.

So anyway, not much we can do unless we add our own hack to counteract Steam.

rlabrecque commented 3 years ago

Hey @timkeo, thanks for the confirmation.

Could you try out your repro case with the latest beta of steam too?

This seems to be in very active development the last few weeks again.

https://steamcommunity.com/groups/SteamClientBeta/announcements/detail/2896339990517078189

Improved support for games that use raw input for controllers

https://steamcommunity.com/groups/SteamClientBeta/announcements/detail/2896340624042995521

Disabled experimental support for more than 4 Xbox controllers pending further testing

cc: @slouken

slouken commented 3 years ago

Hi guys, I'm one of the engineers at Valve who works on input. @timkeo, nice to meet you!

The problem is that when you initialize the Steamworks API, Steam probably doesn't know what kind of input you need. If you don't have an appID, it's giving you the desktop configuration, which defaults to disabling controller input or mapping it to keyboard and mouse. If you're using steam_appid.txt to specify your appID and have 480 in there, you're telling Steam that your application is SpaceWar, which actually has Steam Input mappings and controller input is redirected to Steam Input instead of XInput.

If you have a real Steam game, then you should make sure you're specifying that appID in steam_appid.txt, and then go to the Steam Input settings on the partner page for your app and select the "Generic Gamepad" template.

If you're just doing prototyping and don't have a Steam appID yet, you can put 1456390 in steam_appid.txt, which is an appID set up for game controller testing.

Cheers!

timkeo commented 3 years ago

Thanks @slouken for the response and detailed explanation! I haven't actually developed on the Steam platform before and still learning how things work.

I'll share this information on the Unity forums so others will have better chance of seeing it.

rlabrecque commented 3 years ago

Steamworks.NET does seem to have some role to play here then. As we do set the default AppId to 480 for a good out of box experience.

I'm hesitant to just switch right to 1456390 as the default though as a lot of the examples we have utilize content and permissions that 480 has, such as Lobby and Workshop which 1456390 may not have enabled.

Better documentation around this and pushing people to use their own AppId sooner may help.

slouken commented 3 years ago

If you test it and find things that are missing, let me know and I can enable them.

slouken commented 3 years ago

@timkeo You're welcome! We've been improving our raw input controller support so it works better with Unity. If you have any troubles with the current Steam beta client, please let me know, and I'll take a look.

mle-ii commented 3 years ago

@slouken @rlabrecque Curious if there is a fix, workaround or solution here?

I have been trying to figure out an issue with a game that I'm playing where it seems that the controller input gets into a broken state either when it starts the game outside of steam or if at any time during play the controller disconnects and reconnects, or if the player connects the controller after the game starts. This is with the Unity Legacy Input System if it matters. The game where I'm hitting this issue is Vaheim. I've helped them figure out fixes to other controller issues with Steam/Unity but this one has me stuck. :(

I am also testing with an Xbox One Wireless Bluetooth Controller if that matters, but I'm pretty sure I've repro'd this with a wired 360 controller, though I'll follow up if need be though pretty sure that's not a variable here. And it doesn't solve the issue for those who, like me, use that type of controller.

I wrote a simple unity app that repros the behavior only when SteamWorks.NET is being used. Even starting my app inside or outside Steam without SteamWorks.NET as part of the test app, it does not repro the issue. I've used both the default 480 and 1456390 app ID and they both repro the issues I'm seeing.

The side effect of this is that the Left and Right Trigger end up getting swapped. Normally the Left Trigger should return -1 to 0 and the Right Trigger should return 0 to 1. But when SteamWorks.NET is being used the reverse is true. And also in some situations Steam ends up telling Unity that there are two different controllers connected. It seems like when Steam starts up it uses a default of an Xbox 360 controller, but if you disconnect and reconnect it sees an Xbox 360 controller connected and an Xbox One controller. But it's the same controller. And I can see it sending the swapped data for the trigger and what it should actually be. So in the game I'm playing if you pull the Left Trigger down the game registers both the Left and Right Trigger being pulled down.

It also doesn't seem to have Axis 9 and 10 registered which are the Left and Right Trigger, but separated. So with Axis 9 you get 0 to 1 for LT and for Axis 10 you get 0 to 1 for RT.

Also are there examples somewhere that I can look at for how to use SteamWorks.NET with controller input? That might help me narrow down the issue more.

Or any other things to test out here?

mle-ii commented 3 years ago

@timkeo Not sure you've looked at this any more since you last mentioned finding what was going on, but do you have any ideas on what could be done here? This issue causes bugs in games that use this library with unity when using controllers. Especially when you don't have the controller plugged in before the game starts or the controller disconnects and you reconnect it. You have to restart the game and sometimes steam to get it back to working. :(

@slouken @rlabrecque I've tried a few different things like stopping SteamInput to see if it'd release messing with XInput, but didn't seem to work. I don't see any ways in the API to do anything else that might help remove what timkeo discovered it was doing, guessing that's deeper in the SteamWorks API than the csharp "shim" for the SteamWorks unmanaged library.

I can try more things out but at a loss for what to do here. I am not a game developer, though learning, so I don't have access to the SteamWorks discussion group on the Steam forums to ask there or report the issue.

Can someone see if this can be fixed at a lower level in Steam? Even just unity + steam alone without this library seems to have issues where when you first start up the game with the controller connected it reports a Xbox 360 controller when it's really an Xbox One controller, and if you disconnect and reconnect the controller by say removing and putting the battery back in it then Unity seems to think that there are both an Xbox 360 controller and an Xbox One controller connected. :/

timkeo commented 3 years ago

Unfortunately there's nothing Unity can do about this problem either.

Since Steam is deliberately violating the API contract with XInput, there's no way to prevent this in the XInput implementation, and since XInput is a Microsoft library, we can't change the XInput API to prevent the hack. The only possible work-around is to hack Steam's hack and change the machine code back. Unity absolutely cannot make this kind of change.

This is something Valve will have to fix.

slouken commented 3 years ago

I can take a look at this, can you give me repro steps for a Unity noob? :)

mle-ii commented 3 years ago

Unfortunately there's nothing Unity can do about this problem either.

Since Steam is deliberately violating the API contract with XInput, there's no way to prevent this in the XInput implementation, and since XInput is a Microsoft library, we can't change the XInput API to prevent the hack. The only possible work-around is to hack Steam's hack and change the machine code back. Unity absolutely cannot make this kind of change.

This is something Valve will have to fix.

Figured as much, was hoping to see if I could figure out something in the API wrapper but found nothing.

I can take a look at this, can you give me repro steps for a Unity noob? :)

For sure! Gotta work for about 8 or so hours but after work I'll give you a simple steps for creating a simple project and some project code to repro a few of the things I've mentioned. Thank you!

Thank you both!

mle-ii commented 3 years ago

@slouken Ok, I redid everything and put it here and made it pretty much just a project you follow the log instead of all the UI. https://github.com/mle-ii/ControllerSteamWorksNet

Readme with how to build and repro. Unity package if you want to build it on your own. Along with the 2 most important files if you want to created it manually from scratch.

Also a zip file that contains the version already built.

mle-ii commented 3 years ago

@slouken A couple of comments on things. If you want the version of the "game" repro that shows on screen things rather than just in the logs let me know. On reason I created the console log only version was to make it easer for you to build instead of using the binaries I built myself. And I see in my repro steps I left comments about the text box, I'll fix that.

Finally, if you use a wired Xbox 360 controller it does the same things, you just have to unplug it and plug it back in to simulate the disconnect. It even seems that Unity is being told there are 2 Xbox 360 controllers connected, when it's only that one connected.

Oh and it still repros in the latest version of Steam, don't see a newer version of this Steamworks.NET library, but then I do think it's at a lower level than this library now.

slouken commented 3 years ago

On-screen feedback would be useful. I noticed that this build still uses appid 480, which is guaranteed not to work properly.

mle-ii commented 3 years ago

I'll upload that version, describing how to build it for someone who didn't know unity was... hard. So I gave it up.

It doesn't matter what id is used, I tried both they behave the same. I thought I had the copy for id 1456390 but I must have not put that in my build. It's easy enough to add though.

mle-ii commented 3 years ago

Actually, it seems I might need to rebuild it as it's now crashing after the update I just installed for steam today. :/

mle-ii commented 3 years ago

@slouken Huh, well it seems steam changed a behavior, the app works but only if run through steam now. Running outside of steam it crashes unless I run it from the Unity Editor. Works in the unity editor I just cannot run it by double clicking it in Explorer.

Here's the repro that logs on screen, it has the app id I believe that was mentioned was needed, that same file can be added to the other one as well, but regardless it behaves in the same way. https://github.com/mle-ii/ControllerSteamWorksNet/blob/main/OnScreenDisplayControllerSteamWorksNetMinimalRepro.zip

slouken commented 3 years ago

Can you add me as a Steam friend so we can work on this interactively? My username is slouken

mle-ii commented 3 years ago

These are the APIs I'm using in that repro: https://docs.unity3d.com/2019.4/Documentation/ScriptReference/Input.GetAxis.html https://docs.unity3d.com/2019.4/Documentation/ScriptReference/Input.GetJoystickNames.html

I (and the game I'm playing that has issues) is using the Legacy Input system.

slouken commented 3 years ago

@timkeo, can you add me as a Steam friend so we can interactively diagnose this?

As far as I can tell, if the controller is plugged in when the game starts, everything works fine. The problem happens when the controller is hotplugged while the game is running. At that point Unity sees both the real and virtual controllers, and doesn't map axes 9 and 10 for the triggers. Looking at the debug output here, it looks like Unity is using the XInput API both before and after the hotplug. Maybe what's happening is that Unity thinks that the first (real) controller is associated with a single XInput slot, and is getting XInput data associated with the real controller and raw input data for the Steam virtual controller?

I think it would be helpful if you can reproduce this on your end and let me know what APIs you're calling that detect the real controller (which should be blocked) and we can see if properly blocking those will correctly associate the Steam virtual controller with the XInput state.

slouken commented 3 years ago

So I got this to work.

The problem is that the Steam API init is called too late to affect Unity's initialization, and when the game is added as a non-Steam game, the appid of the shortcut doesn't match the appid in the Steam API init call.

The workaround is as follows:

  1. steam_appid.txt should contain 1456390
  2. add the executable as a non-Steam game
  3. run this URL: steam://forceinputappid/1456390 (this needs to be done each time Steam starts)
  4. Launch the game from Steam

This guarantees that the game input hooks are set by Steam by the time Unity initializes, and that Steam knows what configuration to use.

These steps are needed for testing and debugging. Full Unity Steam games with their own appinfo and controller configuration should work fine when launched from Steam.

If you're using an Xbox controller and you don't want Steam's configuration support, you can simply uncheck Xbox Configuration Support in Steam's Controller Settings and your controller will work as expected both with and without Steam.

@timkeo I'll bring this up as part of the larger conversation with Unity about improving Steam support.

mle-ii commented 3 years ago

@slouken Glad to hear you got it figured out. That said I'm not 100% clear on your responses.

Full Unity Steam games with their own appinfo and controller configuration should work fine when launched from Steam.

What do you mean by this? You mean as it stands right now Unity games should work fine with Steam right now? If so that's not the case, Valheim is currently having the behavior we repro'd the other day. I might be misinterpreting what you're saying, or perhaps there's a fix coming for this?

These steps are needed for testing and debugging. Full Unity Steam games with their own appinfo and controller configuration should work fine when launched from Steam.

I'm guessing these aren't steps players/users will need to do to get the games, such as Valheim, working for them. If they are it's not clear to me what the steam url would be in those cases. I'll see if I can get those steps to work with my test app.

If you're using an Xbox controller and you don't want Steam's configuration support, you can simply uncheck Xbox Configuration Support in Steam's Controller Settings and your controller will work as expected both with and without Steam.

For some reason I couldn't get this working on my setup, I swore I did like you did when you showed it to me but I couldn't get it to work. When I unchecked the Xbox option the controller input wouldn't work at all. I can try again later but I tried a few different things and none seemed to behave like it did for you. Could be something about my configuration that is in a weird state.

mle-ii commented 3 years ago

I ran those 4 steps, it repros the same way as it did before. If you disconnect the controller during game play and reconnect it, then it will swap triggers and lists 2 different controllers connected when there is only one.

I'm disconnecting the controller to simulate it getting disconnected either by unplugging or going to sleep.

Are you perhaps on a newer build than what is publicly released?

slouken commented 3 years ago

I had some debugging enabled where I completely blocked non-Steam controllers, oops!

I'm digging into it now, thanks.

slouken commented 3 years ago

This is fixed for the next Steam beta client update, dated 6/15/2021 or newer. You'll still need to follow the 4 steps for correct testing.

Thanks!

mle-ii commented 3 years ago

No idea if it fixes the case that was first reported for this issue, but I can confirm that the controller now behaves as I expect it both in the test app and in the game where I first noticed the issue when using the Steam Beta.

Thank you all for helping to narrow this down and to @slouken for fixing the bug.

slouken commented 3 years ago

Great! Thanks for confirming the fix!

diegoaraujo443 commented 2 years ago

@slouken Hi, I'm having a similar problem. I'm already running the game via steam (downloading direct in my account). The game works fine, but when it initializes no controller works unless I unplug and plug it in again. If I do it, every controller I have works fine (Xbox360, PS4, Generic USB). The keyboard recognizes normally everytime. The game uses the new input system as well. I filed tickets via Steam and Unity forums, but no one could help me. Any idea how I can fix this bug?

diegoaraujo443 commented 2 years ago

@timkeo @slouken Hi again. Via Unity, my controller works perfectly fine, but via Steam, I have to plug after the game initialized.

I have run a lot of tests, and that's what's happening (game lauching via steam):

So, it seems like a process (some method, some kind of refresh) happens on steam when I plug/unplug controllers, if any of you could adress me which process is that, I could execute it on the start of the Steamworks.NET script, and that alone would probably be enough.

Thanks for the help, I'm really desperate. Right now that's the only thing preventing me from launching my game.

mle-ii commented 2 years ago

@diegoaraujo443 Huh, yeah, that does seem like a regression. Wonder when that happened, I haven't played the game I normally play with a controller for a while so not sure when that broke again. :( I see a similar behavior here as well.

diegoaraujo443 commented 2 years ago

@mle-ii So, it seems that it's a Steamworks.NET issue right? Do you know how do proceed in this case? I'm fairly new at coding, and just finish my first game. Any advice would be very helpful and appreciated.

diegoaraujo443 commented 2 years ago

@mle-ii Hi again.

So, I have changed the wrapper to facepunch, and, the exactly same problem occurs. So I believe it can only be a Steam issue, some new client update maybe.

@slouken can you give me any information that may help me with this issue?

mle-ii commented 2 years ago

Well, last time the issue was with the Steam client and not Steam.NET. Unfortunately I don't know where regular users can report issues with Steam, maybe somewhere in the steam forums or the steam client UI? There is a forum for developers to report issues but I couldn't get access to it because I don't have an official app/game that I'm working on.

diegoaraujo443 commented 2 years ago

Thanks.

I did reported to steam as a dev, but no answer yet.

Just one more information I found out by chance:

mle-ii commented 2 years ago

Well, that's a bummer, and seems you're not getting much response here either. :(

If you have the ability to do so, be sure to update the case you created there with this last detail and a link to this issue comment thread. Likely they made a change to fix some other issue for controllers and caused this regression.

I have to do what you're doing to make it work the last time I tried, which is what it was like before they did that recent fix. And unfortunately I didn't even ever see the fix that @slouken did listed in the patch notes when they did fix it.

mle-ii commented 2 years ago

Oh and be sure to note the date/time when you noticed it broke. Unfortunately I wasn't playing games on steam for a while as I had other things going on so I don't know when it regressed. :(

slouken commented 2 years ago

Can you guys check today's beta (dated December 16, 2021) and see if that's fixed?

mle-ii commented 2 years ago

Can you guys check today's beta (dated December 16, 2021) and see if that's fixed?

I will tonight after work. Thank you for looking into this.

mle-ii commented 2 years ago

Can you guys check today's beta (dated December 16, 2021) and see if that's fixed?

Sorry, same behavior in both beta and regular client, though they both seem to have the same update data. https://store.steampowered.com/oldnews/?feed=steam_client https://steamcommunity.com/groups/SteamClientBeta

I tried these 3 and none worked: 1) Having the controller on before starting up Steam Client 2) Connecting the controller after starting Steam Client 3) Using big picture mode

Then starting Valheim (a unity game) up in all 3 of those scenarios. In all 3 the xbox controller is not seen.

To get the controller to be seen I have to turn off and back on the controller after I start Valheim.

I can try another game, but you are not able to reproduce the bug in the current version? I suppose it could be a new bug in the game I'm playing but it's behaving similarly to before. Though before it would see 2 different controllers when doing that.