FFBArcadePlugin icon indicating copy to clipboard operation
FFBArcadePlugin copied to clipboard

After running Super Model 3 games with force feedback, it breaks force feedback on other emulators

Open ericharbison opened this issue 1 year ago • 48 comments

I've been setting up multiple racing games for a racing cabinet. I noticed sometimes forcefeedback stopped working after playing certain games, then launching other games. After trying a bunch of scenarios, I have determined that running a game like Sega Rally 2 (Super Model 3), then trying to run Sega Rally 1 or Sega Rally 3, force feedback wont work. Emergency Room Ambulance also breaks other emulators after running it.

ericharbison avatar May 11 '24 21:05 ericharbison

Funny, I was about to post about a similar issue. I don't remember this happening with Model 3, I'd have to double check. But this happens with MAME, I've been dealing with it for years. The problem is exactly as you described, FFB will completely stop working for other games/emulators after starting and exiting a MAME game. It doesn't always happen but it happens pretty frequently. The only fix I know off is to restart my PC.

If there is a lingering process or other dependency that can be terminated through a script on game exit that would be great.

Yardl3y avatar May 13 '24 00:05 Yardl3y

Funny, I was about to post about a similar issue. I don't remember this happening with Model 3, I'd have to double check. But this happens with MAME, I've been dealing with it for years. The problem is exactly as you described, FFB will completely stop working for other games/emulators after starting and exiting a MAME game. It doesn't always happen but it happens pretty frequently. The only fix I know off is to restart my PC.

If there is a lingering process or other dependency that can be terminated through a script on game exit that would be great.

That was my first thought too. What can I kill after existing the emulator to keep force feedback working. I haven't figured it out yet. I have bigbox setup and even created a batch file to launch supermodel 3 and was going to kill the process on exit, but can't figure out which process needs to get killed. For now I reboot my PC.

ericharbison avatar May 13 '24 02:05 ericharbison

I took a look at the code. Looks like SuperModel 3 and MAME use the same code in the FFB plugin. I haven't setup FFB in MAME yet, but will probably experience the same issue you were seeing with MAME too. Going to see if I can fix the exit code in the FFB plugin.

ericharbison avatar May 13 '24 15:05 ericharbison

Nice, I didn't think to do that. Let me know if you figure something out!

Yardl3y avatar May 14 '24 01:05 Yardl3y

I think I figured it out. I changed the exit code in MAMESupermodel.cpp to this:

static int __stdcall ExitHook(UINT uExitCode) { //TerminateProcess(GetCurrentProcess(), 0); MH_DisableHook(MH_ALL_HOOKS); Sleep(1300); ExitProcess(0); return 0; }

I need to do more testing, but so far I haven't had any issues. I don't know if the sleep is needed. If I can verify this for a few days I'll recommend the code change to the devs. It seems like the TerminalProcess was causing the issue. The M2 emulator was was doing an ExitProcess(0), so I tried that. It only worked half the time, but was better. Then I added the MH_DisableHook(MH_ALL_HOOKS); and Sleep before exiting process, and now it seems to work all the time and I've had zero issues launching games on different emulators. I've tried launching different games after launching SuperModel 3 Games about a dozen times now and it just works.

EDIT:

I did find an issue that I will need to investigate. If I run The same or different SuperModel 3 games twice in a row it breaks other emulators like before. If I Run a SuperModel 3 only one time and a different emulator it works every time.

ericharbison avatar May 14 '24 17:05 ericharbison

I think I need to give up. I seems like it has something to do with not freeing the MAME.dll library on exit or possibly something else on exit. I can't get it to be consistent.

Doing this seems to work sometimes, but then it wont work.

static int __stdcall ExitHook(UINT uExitCode) { FreeLibrary(ProcDLL); TerminateProcess(GetCurrentProcess(), 0); return 0; }

ericharbison avatar May 16 '24 19:05 ericharbison

Good effort man, maybe you'll get it eventually. Unfortunately Boomslangnz isn't working on this plugin anymore.

Yardl3y avatar May 17 '24 04:05 Yardl3y

I think I have it officially working. In the MAMESupermodel.cpp file I changed:

First I moved the HWND hWnd; outside of the WinMain() function so that I could access it later.

In the FFBLoop() function I changed:

Original:

if (StopConstant == 255) { MotionFalse = true; }

New:

if (StopConstant == 255) { MotionFalse = true; triggers->Constant(constants->DIRECTION_FROM_LEFT, 0); triggers->Constant(constants->DIRECTION_FROM_RIGHT, 0); StopConstant = 0; PostQuitMessage(0); CloseWindow(hWnd); FreeLibrary(ProcDLL); return; }

These are the main things that fix this:

PostQuitMessage(0); CloseWindow(hWnd); FreeLibrary(ProcDLL);

I noticed that the WndProc WN_DESTROY is never called, so I'm doing the PostQuitMessage(0), then I call the CloseWindow which seems to destroy the MAME.dll Window that was created earlier for the MAME.dll file. Finally I destroy the MAME.dll connection.

I left the ExitHook the same:

static int __stdcall ExitHook(UINT uExitCode) { TerminateProcess(GetCurrentProcess(), 0); return 0; }

I have been playing different games, sometimes multiple times with exiting and then playing other emulators and it seems to just work now.

ericharbison avatar May 19 '24 17:05 ericharbison

Nice! Can you post the entire script you’re using? I can test it thoroughly to see if it works for me. This should fix the issues with MAME too!

Yardl3y avatar May 19 '24 18:05 Yardl3y

Let me do a little more testing first on different machines.

ericharbison avatar May 19 '24 18:05 ericharbison

I found some oddities on another machine. This code listed below seemed to do better.

if (StopConstant == 255) { MotionFalse = true; triggers->Constant(constants->DIRECTION_FROM_LEFT, 0); triggers->Constant(constants->DIRECTION_FROM_RIGHT, 0); StopConstant = 0; TerminateProcess(hEdit, 0); PostQuitMessage(0); CloseWindow(hWnd); return; }

But while testing I discovered something new. At least for SuperModel, When I copy in the files and overwrite the old ones (opengl32.dll, MAME64.dll, and SDL2.dll). opengl32.dll is the updated file that I've been making changes to. When I do this, it seems to reset the issues. If I restart my machine and try to play games again, its broken again because I didn't overwrite the files. So now I'm wondering if I just rename these files and name them back again on Exiting SuperModel or MAME, that might just fix the issue. I'll have to do some testing, but it's getting late. This would be a hack, but at this point I don't care. I'll put some code on exit to rename the files and name them back again to see if that fixes it. If not I can share a batch script that can do this on exit.

I'll try to get something for you to test on your machine in the next few day. :)

ericharbison avatar May 20 '24 00:05 ericharbison

I don't think renaming the files does anything. When I have some time I want to see if I can fix the WndProc destroy. It doesnt appear to be running on exit, which is why my code chage seems ro get closer to the solution.

ericharbison avatar May 20 '24 13:05 ericharbison

Let me know if you need me to test anything on my end.

Yardl3y avatar May 20 '24 18:05 Yardl3y

Hey, just checking to see if you made any progress with this issue?

Yardl3y avatar Jun 03 '24 04:06 Yardl3y

Im rewriting the ffb code to not use the mame dll directly. Im getting closer to finishing.

ericharbison avatar Jun 03 '24 11:06 ericharbison

Good to hear! I've been having issues with Demul too. I would think your fix could potentially solve that as well.

Yardl3y avatar Jun 04 '24 03:06 Yardl3y

I think I finally have it working. I made extensive code changes to the MAMESupermodel code to separate out the MAME dll from the code. I got that working but it ultimately didn't make a difference. But it did give me much simpler code to debug the actual issue. After getting that to work with some additional code changes, I went back to the original code and added the very simple bug fix only and it works. There is a chance that after playing for many hours it may have issues, but so far it is now gracefully exiting the MAME/Super Model/Flycast. I've only tested it with Super Model so far but it's the same code as the other 2 emulators as well. The bug is that on my newest PC, it wouldn't happen very often with my original bug fix, but on my new but not as fast PC it happened often. This is because when exiting these games you have less than 1 second to run code to clean up any processing that are still running before the application shuts down. This is barely any time to close all of the processes that need to close and it would end up take too long to close and not do the final procedure in the DllMain file. I noticed on my slower machine that it still had forcefeedback in the queue and would take a few cycles to finish running those which would make the application end before running the final cleanup procedure. My fix is to alert the final procedure in DllMain the moment mame_stop happens which is the first indicator that the application is closing.

ericharbison avatar Jun 09 '24 02:06 ericharbison

Nice man! Are you going to create a fork?

Yardl3y avatar Jun 09 '24 02:06 Yardl3y

Im going to need to create a fork. Im going on vacation for a few days, but will try when I get back.

Sent from my Verizon, Samsung Galaxy smartphone Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Yardl3y @.> Sent: Saturday, June 8, 2024 9:56:38 PM To: Boomslangnz/FFBArcadePlugin @.> Cc: ericharbison @.>; Author @.> Subject: Re: [Boomslangnz/FFBArcadePlugin] After running Super Model 3 games with force feedback, it breaks force feedback on other emulators (Issue #68)

Nice man! Are you going to create a fork?

— Reply to this email directly, view it on GitHubhttps://github.com/Boomslangnz/FFBArcadePlugin/issues/68#issuecomment-2156284909, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AD3AIBP7O5NRSM7XAQIKRH3ZGO76NAVCNFSM6AAAAABHSGXOU6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJWGI4DIOJQHE. You are receiving this because you authored the thread.Message ID: @.***>

ericharbison avatar Jun 09 '24 12:06 ericharbison

Any chance you can take a quick look at the code for Demul when you have a chance? I think that one might be affected as well and your fix might work for it too.

Yardl3y avatar Jun 09 '24 13:06 Yardl3y

I can take a look. I have demul games that I plan to use as well


From: Yardl3y @.> Sent: Sunday, June 9, 2024 8:26:39 AM To: Boomslangnz/FFBArcadePlugin @.> Cc: ericharbison @.>; Author @.> Subject: Re: [Boomslangnz/FFBArcadePlugin] After running Super Model 3 games with force feedback, it breaks force feedback on other emulators (Issue #68)

Any chance you can take a quick look at the code for Demul when you have a chance? I think that one might be affected as well and your fix might work for it too.

— Reply to this email directly, view it on GitHubhttps://github.com/Boomslangnz/FFBArcadePlugin/issues/68#issuecomment-2156606410, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AD3AIBMBVNVJIDOZ4FREUS3ZGRJY7AVCNFSM6AAAAABHSGXOU6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJWGYYDMNBRGA. You are receiving this because you authored the thread.Message ID: @.***>

ericharbison avatar Jun 10 '24 01:06 ericharbison

I made a few more tweeks to the MAME and Supermodel code changes. When I started to set up MAME forcefeedback I noticed some issues. I think I have the issues straightened out, but want to finish setting up the rest of my games and test some more before forking the branch. I also notice Le Mans 24 force feedback is wrong. Im making some code chages for that Supermodel game. I noticed I don't have any of the demul games installed that use forcefeedback. Ill have to get that setup before I can test it.

ericharbison avatar Jun 17 '24 15:06 ericharbison

I got Demul Setup with ATV Track and Smashing Drive. At first I thought ATV Track force feedback didn't work at all, but after some testing, if you press start button before waiting 15-20 seconds after launching the game force feedback doesn't work. That might be the game not initializing the force feedback until some time after it launches. These used to be arcade games so I'm not sure that behavior could be fixed in this code.

I'm pretty happy with my changes to MAME and Supermodel. I'll be creating a fork soon.

ericharbison avatar Jun 20 '24 13:06 ericharbison

I created a fork: https://github.com/ericharbison/FFBArcadePlugin

I added the opengl32.dll file that needs to replace the old one in the Supermodel directory and the dinput8.dll file that needs to go into the MAME folder.

ericharbison avatar Jun 20 '24 14:06 ericharbison

Awesome! I'll give this a try. So to implement your fixes I just need to place the two dll files in the directories you mentioned? Everything else remains the same?

Yardl3y avatar Jun 24 '24 13:06 Yardl3y

Yep. The other files I used were from the latest release. Both of these files are 64bit versions. Just replace the one dll from mame and one dll for supermodel. Also, I recently got flycast installed. Im not seeing issues with flycast using the release version.

ericharbison avatar Jun 24 '24 14:06 ericharbison

Did you get a chance to try it? After testing Flycast some more. It looks like the original code (not my changes) is causing similar problems. I started using the update code version to see if that fixes it, but it looks like Flycast doesn't send a mame_start or mame_stop. The only way to have Flycast send a mame_stop would be to modify that emulator to send a mame_stop on exit. It should work if Flycast sent the mame_stop.

ericharbison avatar Jun 28 '24 18:06 ericharbison

Sorry for the delay! I just tested it and as far as FFB not breaking, it looks like you nailed it! I went in and out of Ace Driver for MAME and Daytona USA 2 for Model 3 a number of times following that up with Daytona USA for Model 2 and Dirty Drivin' for Teknoparrot and FFB didn't break a single time.

The bad news is that FFB for Daytona 2 in Model 3 is really off now. It feels very different than when playing with the original opengl32.dll file, I alternated between the two back to back just to make sure that was the root cause. For me, with your dll the wheel is very jerky and registers false FFB events. For example, if I'm turning a corner and the wheel feels stiff from the centering spring, it will randomly jerk and get soft/lose the stiffness. Can you check if the same happens to you?

As for MAME, it feels fine, but I have been testing only with Ace Driver for weeks haha, and while it feels fine for that game, I'm not sure about others.

Yardl3y avatar Jun 30 '24 22:06 Yardl3y

Thanks for the input. I can rebuild it with the latest code and post an update. I had actually been messing around with daytona 2 and lemans, so its possible i messed something up. I didnt change any of the other games. Ill rebuild it with the latest dev branch.

ericharbison avatar Jun 30 '24 23:06 ericharbison

I rebuilt the fix with the latest dev release. I noticed that the latest release already fixed LeMans24, and Daytona 2 feels different then what I was used to now. Let me know if it fixes the issue you saw with Daytona 2.

Release: https://github.com/ericharbison/FFBArcadePlugin/releases

ericharbison avatar Jul 01 '24 00:07 ericharbison