elishacloud / Silent-Hill-2-Enhancements

A project designed to enhance Silent Hill 2 (SH2) graphics and audio for the PC. It also includes scripts to build or modify SH2 audio files (SFX, BGM and Dialog).
http://www.enhanced.townofsilenthill.com/SH2/
zlib License
597 stars 42 forks source link

[Consideration] Xidi as an alternative to XInput Plus #620

Closed r2rX closed 1 year ago

r2rX commented 2 years ago

Hello there,

This isn't an issue but I wanted to bring to your attention a very cool XInput to DInput project called Xidi. It's robust and easy to use. I've tested it with Silent Hill 2, 3 and 4 with great success (tested in Windows and Linux). All analog sticks, buttons, triggers and force feedback works. Silent Hill 2 (as well as 3 and 4..well 4 requires a complimentary .ini file but that's besides the point) only requires one file from Xidi, dinput8.dll, and that's it.

I know XInput Plus is absolutely fine but I thought to share this anyway. Might be worth testing. :) If not, all good.

elishacloud commented 2 years ago

The second time around, the request is for only those attached controllers that specifically support force feedback.

We have a DirectInput wrapper in the game's module. We could add an option to change this request in the game such that it requests all controllers rather than just the ones with force feedback.

samuelgr commented 2 years ago

I tested vanilla SH2 PC with Xidi and, interestingly, the DirectInput controller (RumblePad 2) still was not working with Xidi.

In this log I see only one enumeration attempt, this one specifically requesting controllers with force feedback. It's interesting, the game really tries hard to get a force feedback controller.

My guess is that if force-feedback-only enumeration comes back empty then the game re-attempts enumeration for all controllers and picks the first one that it finds.

Could you please capture a log with this test build of Xidi? I modified it so that the Xidi virtual controllers won't show up in a force-feedback-only enumeration.

Xidi-v4.0.4-dev.6.1+fb372557.dirty.zip

Polymega commented 2 years ago

Could you please capture a log with this test build of Xidi? I modified it so that the Xidi virtual controllers won't show up in a force-feedback-only enumeration.

With this build my RumblePad 2 is now working with the game, but ForceFeedback/vibration unfortunately doesn't work. Here is that log: Xidi_DInput8_sh2pc.exe_6620.log

Now, here's where things get interesting:

On my laptop, everything works fine, including vibration with the RumblePad 2. Even when using your previous "dirty" build (seen here), the RumblePad 2 works/vibrates with the game on my laptop. Here is a log for this on my laptop:

^ btw, it's amazing that this DirectInput controller is vibrating once again with the game. Never thought I'd see the day!

So this begs the question: Is there something on my desktop creating a conflict? I don't use any third party software like DS4Windows, and XInput Plus is fully removed from the game folder. I'm not sure what's going on? This might be a blessing though, as perhaps others would run into the same issue?

@elishacloud I'd be curious to see if the game works for you with Xidi if you also happen to own a DirectInput controller.

samuelgr commented 2 years ago

Right, so as I suspected the game first tries to look for force feedback controllers and, if it doesn't find any, it expands the search to all controllers.

With this build my RumblePad 2 is now working with the game, but ForceFeedback/vibration unfortunately doesn't work. Here is that log: Xidi_DInput8_sh2pc.exe_6620.log

From this log, here's what I mean:

[11/03/2022 20:41:10] [D] Starting to enumerate DirectInput devices.
[11/03/2022 20:41:10] [D] Enumerate: dwDevType = 0x00000004, dwFlags = 0x00000101.
[11/03/2022 20:41:10] [D] Enumerate: System has no XInput devices, so Xidi virtual controllers are being presented to the application after other controllers.
[11/03/2022 20:41:10] [D] Finished enumerating DirectInput devices.
[11/03/2022 20:41:10] [D] Starting to enumerate DirectInput devices.
[11/03/2022 20:41:10] [D] Enumerate: dwDevType = 0x00000004, dwFlags = 0x00000001.
[11/03/2022 20:41:10] [D] Enumerate: System has no XInput devices, so Xidi virtual controllers are being presented to the application after other controllers.
[11/03/2022 20:41:10] [D] Enumerate: DirectInput device "Logitech RumblePad 2 USB" is being presented to the application.
[11/03/2022 20:41:10] [I] Binding to non-XInput device "Logitech RumblePad 2 USB". Xidi will not handle communication with it.
[11/03/2022 20:41:10] [D] Application has terminated enumeration.

The very first enumeration in the log is the one that is used for your module's logging. I am skipping over that one for convenience.

Game's first enumeration, dwFlags = 0x00000101 which mean force feedback devices attached to the system. No results (because of the modifications I made, Xidi virtual controllers don't enumerate as supporting force feedback).

Game's second enumeration, dwFlags = 0x00000001 which means all devices attached to the system. Xidi does the right thing and presents the Logitech controller first, and as soon as the game sees it the game binds to it and stops the enumeration.

@Polymega you might be able to get force feedback working with the Logitech controller on your desktop by installing the Logitech Gaming Software (pick Windows 10 from the drop-down menu to see it). On the laptop it's no surprise that the controller works with both builds of Xidi - the system reports that it supports force feedback, so Xidi presents it first during the initial force-feedback-only enumeration, and the problem is avoided.

Polymega commented 2 years ago

Game's second enumeration, dwFlags = 0x00000001 which means all devices attached to the system. Xidi does the right thing and presents the Logitech controller first, and as soon as the game sees it the game binds to it and stops the enumeration.

Is this a change you'd commit to Xidi, or was this a one-off for us to test with? I ask...

Elisha wrote: We have a DirectInput wrapper in the game's module. We could add an option to change this request in the game such that it requests all controllers rather than just the ones with force feedback.

...to see if we should pursue this for the game?

@Polymega you might be able to get force feedback working with the Logitech controller on your desktop by installing the Logitech Gaming Software (pick Windows 10 from the drop-down menu to see it). On the laptop it's no surprise that the controller works with both builds of Xidi - the system reports that it supports force feedback, so Xidi presents it first during the initial force-feedback-only enumeration, and the problem is avoided.

What's interesting is I don't have Logitech Gaming Software installed on my laptop. So I go back to wondering what's the difference between both of my PCs to allow my laptop to both work and vibrate with Xidi? 🤔

samuelgr commented 2 years ago

Is this a change you'd commit to Xidi, or was this a one-off for us to test with?

The Xidi build was for a one-off test, and I was just explaining the contents of the log. dwFlags is a parameter that the game passes to DirectInput when it requests an enumeration. I'm not suggesting a change to Xidi because it is already responding correctly to the requests it gets from the game.

We can try to work around this behavior quirk with a change to the DirectInput wrapper. The one thing I still wonder about is if the game uses these two enumerations as a way of deciding whether or not it should try to use force feedback at all.

Polymega commented 2 years ago

@samuelgr I tested your newest release build (released two days ago) and received the following error in Win7. I figured I'd share this here in case Elisha has a suggestion, if desired:

Capture

Polymega commented 2 years ago

Also, a follow-up to the Rumblepad 2 not being detected on my Win10 desktop: Through some more tests I realized that, under Device Manager, my Win7 desktop and Win10 laptop were correctly identifying the controller, but on my Win10 desktop, it was being detected as a generic "USB input device."

I downloaded the Logitech Gaming Software on this PC to hopefully get the drivers needed and that did the trick; Xidi now works with the Rumblepad 2 and vibration works in the game with Xidi as well.

I could've sworn I never downloaded the Logitech Gaming Software on my other computers, but I might have many years ago and forgot about it. Either way, this was a good lesson for myself to help troubleshoot others in the future, as I'm confident there will be others who will run into this predicament in time.

Thanks and sorry for all the trouble here, Samuel.

elishacloud commented 2 years ago

I figured I'd share this here in case Elisha has a suggestion, if desired:

Capture

This just means that the Xidi dll is still trying to load a part of the VC runtime environment. This should have been fixed by the requested change listed here.

samuelgr commented 2 years ago

This just means that the Xidi dll is still trying to load a part of the VC runtime environment. This should have been fixed by the requested change listed https://github.com/elishacloud/Silent-Hill-2-Enhancements/issues/620#issuecomment-1293956797.

That change should indeed fix the error. I've been making it on a one-off basis to upload test builds to this thread, but I haven't done it in the official Xidi repo.

Xidi now works with the Rumblepad 2 and vibration works in the game with Xidi as well.

Great to hear. There is still a very valid concern that a user could try to use a non-force-feedback non-XInput controller with the game. The same enumeration issue we've been discussing would happen, and the user's controller wouldn't work.

Polymega commented 2 years ago

There is still a very valid concern that a user could try to use a non-force-feedback non-XInput controller with the game. The same enumeration issue we've been discussing would happen, and the user's controller wouldn't work.

Absolutely. If this issue happened to one, it'll happen to many. It'd be best to be proactive about this and get rid of the second enumeration pass the game does. @elishacloud if you're still game to look into this, that'd be a great help!

elishacloud commented 2 years ago

Ok, I put an update in for this. If a device with this text "Xidi Virtual Controller" is detected then the force feedback filter is removed. This should fix the issue.

Here is the test build: d3d8.zip

Polymega commented 1 year ago

@samuelgr

#620 (comment) That change should indeed fix the error. I've been making it on a one-off basis to upload test builds to this thread, but I haven't done it in the official Xidi repo.

I happened to check your repo today and saw a new update and tested it out. I no longer receive this error when using Xidi with Win7. :+1: Just wanted to test and let you know!

samuelgr commented 1 year ago

I no longer receive https://github.com/elishacloud/Silent-Hill-2-Enhancements/issues/620#issuecomment-1306406132 when using Xidi with Win7. 👍 Just wanted to test and let you know!

This is not due to a deliberate change on my part. It could just be a side effect of a code change or even just an updated version of Visual Studio on my machine.

On the subject of linking MSVC runtimes, as of https://github.com/samuelgr/Xidi/commit/f0cd9ec60a70f4033e5407a49f79c00056f55933 the build settings are located in separate files (property sheets) rather than being embedded in the projects themselves. So if you need to change to static linking when building Xidi, all you would have to do is change this one line to say "MultiThreaded" instead of "MultiThreadedDLL" in Properties/BuildSettings.props (there is a corresponding line for the Debug configuration as well).

Polymega commented 1 year ago

@samuelgr I'm prepping the project site for notes about Xidi. Question for you: I know with Xidi that, if it's running in "XInput mode" you can disconnect an XInput controller and connect a totally different one and the game will accept it like nothing's change. Is the same true for "DirectInput mode" as well? I only have one DInput controller, so I can't swap them while the game is running to test/know.

Thanks!

Polymega commented 1 year ago

Xidi will be coming with our next project update which should be in the near future. Thanks again r2rx for the suggestion and connections and thank you Samuel for your work on Xidi!

samuelgr commented 1 year ago

@Polymega There isn't really a "DirectInput mode" and an "XInput mode" per se. Xidi will do hot-plugging for XInput controllers and won't do anything at all for non-XInput DirectInput controllers (these are just passed through directly to the system without any special handling).

JaegerFox commented 1 year ago

the application was able to start correctly error (0xc0000142)

Polymega commented 1 year ago

There might be an external dependency Xidi needs to run. See these tickets below which we think might be related to the error you're receiving:

You can test this by temporarily removing dinput8.dll from the game's main folder and seeing if the game will launch then.

JaegerFox commented 1 year ago

You can test this by temporarily removing dinput8.dll from the game's main folder and seeing if the game will launch then.

I forgot to mention that I am using Windows 8.1 and I have the latest vc runtime libraries installed. if I have come here it is because I definitely know that it is a issue related to xidi. another thing... I'm using SCPdriver, I don't know if that affects anything.

elishacloud commented 1 year ago

the application was able to start correctly error (0xc0000142)

@JaegerFox, Can you try with this Xidi update: dinput8.zip

JaegerFox commented 1 year ago

@elishacloud still not working, the same code error

elishacloud commented 1 year ago

Can you try again with this updated module? I removed enhanced processor instructions and removed runtime requirements. Just unzip this into the Silent Hill 2 folder where the sh2pc.exe file exists.

Here is the update: dinput8.zip

JaegerFox commented 1 year ago

Can you try again with this updated module? I removed enhanced processor instructions and removed runtime requirements. Just unzip this into the Silent Hill 2 folder where the sh2pc.exe file exists.

Here is the update: dinput8.zip

that worked, everything works fine

elishacloud commented 1 year ago

Ok, great.