I think that Microsoft recently updated Windows 10 for the new Xbox series X controller and their Xbox Accesories app. Maybe they changed something that broke the dinput.dll fix that has been used in Rayman 2 for years now.
Can someone confirm if they are having this crash too on an updated Windows 10 machine ?
If it happens to everyone else, does someone actually now how to replicate the fix with updated dlls ? (I'm a Software Engineer but honestly I don't have any experience on modding or hacking compiled binaries).
Also, I tried the dinput.dll from the keyboard remapping tool (viewtopic.php?f=89&t=25320) and the game works nice with the remapped keys, but not the controller (I assume that the dll is the original with just the remapping modifications, and not the actual fix).
Would be awesome if I can fix this, I just love this game. I guess I will have to go with Dreamcast/PlayStation emulation if I don't fix this :/
So... I solved the issue, and the solution is pretty creative xD.
- Download the dinput.zip from the latest release here. Extract the dinput.dll file in your Rayman 2 game folder (where the Rayman2.exe file is). If you downloaded the v18.104.22.168 release or previous, you must follow the next step. If your version is above v22.214.171.124, then you are done, your controller should work!
- Download the controller fix for Rayman 3 here (yes, the Rayman 3, not the Rayman 2 fix). Extract the dinput8.dll file in your game folder, where you extracted the dinput.dll before.
First I realised that the source code of the fixed dinput.dll is on the link that you provided before. You can download it here. It was made in Visual Studio 2010 but I had no problem compiling it on VS Comunitty 2019. Still the new compiled dll made the game crash.
I'm definitelly not in the C++ world so I couldn't do much with the source code, except from understanding it at a high level. There are just a bunch of files with few code and the original author made a really useful comment about what was the original Rayman 2 bug about. Basically the game expects that the gamepads are given first in the device enumeration while the official Microsoft API does not guarantee this. So the whole project is a dinput.dll wrapper that calls the original API, sorts the devices and returns it to the game. I tried to do some debugging but it seemed that the code was not even being executed, so probably the problem was in the way that the official API was hooked at the start (maybe this does not make any sense at all).
I kept diving on the internet and also tried out the dinput8.dll fix for Rayman 3, which is working perfectly on Rayman3 but, as expected, not on Rayman 2. I accidentally found out this project on GitHub, which is another dinput.dll wrapper to transform dinput calls to dinput8 (I don't even know what are this APIs, I just assume that it is a more modern version of dinput). The project was made for old games in general and has a compatibility list (not Rayman 2 ). Also the latest commits are from the previous month so it seems that it is still active so it would probably won't make my game crash.
So I came up with the crazy idea of putting the dinput.dll from dinputto8 project along with the fixed Rayman 3 dinput8.dll, with the hope that Rayman would call the wrapper dinput, and this would call the Rayman 3 fixed dinput8. Guess what, it worked... . The inputs were a bit dissordered though, probably because of the fact that the dinput8.dll file was made for Rayman 3, but still totally playable and probably easy to fix with some remapping tool.
Just as a curiosity and because I wanted to have some fun with the C++ code, I cloned the dinputto8 repo and tried to just copy the algorithm that sorts the input devices in the Rayman 2 fix project, since I could find that both were wrapping the same dinput API interfaces (IDirectInputA). So I copied the CreateDevice function code and made one minor tweak to adapt to the new implementation. I compilled the new dinput.dll and it worked!! Now I have the original mappings and don't need to use the Rayman 3 dinput8.dll anymore.
I will probably contact the author of the dinputto8 project, he may want to add this changes and have our beloved Rayman 2 in the compatibility list . If I'm right and new Windows 10 updates are no longer compatible with the old dll fix, I hope that this will help others and last for another 8 years.
I created a pull request on the dinputto8 project, with my changes for making it compatible with Rayman 2 without the need of the Rayman 3 fix. Let's see if the author answers soon and makes a release, if that does not happen you can either compile my forked project or I will probably make my own release.
Pull request: https://github.com/elishacloud/dinputto8/pull/14
dinputto8 author merged the pull request with some modifications. I have confirmed that this modifications didn't break the fix and the binary is still working. Whenever the author releases the next version (current is v126.96.36.199), it should contain the fix and we no longer need the Rayman 3 fix.