mtasa-blue icon indicating copy to clipboard operation
mtasa-blue copied to clipboard

DSOAL support to restore DirectSound3D (3D spatial audio) and EAX (environmental reverb)

Open ThreeDeeJay opened this issue 1 year ago • 19 comments

Is your feature request related to a problem? Please describe.

Even though San Andreas supported DirectSound3D (3D spatial audio) and EAX 1-4 (environmental reverb), both were mostly broken since Windows Vista. So to restore those features, you would normally need to use a DirectSound3D wrapper like Creative ALchemy (for Creative sound cards) or DSOAL (open-source alternative for any sound card), which works in base GTA:SA, but MTA seems to be hard-coded to look for the drop-in file (dsound.dll) in System32/SysWOW64 even after applying a registry tweak that fixes that in other games. So to use those wrappers, we can just replace the DLL in System32/SysWOW64, but that's not recommended as it reportedly can cause system stability and app compatibility issues.

Describe the solution you'd like

My proposed solution is to implement DSOAL directly into MTA or allowing to load dsound.dll from the game folder so it doesn't require replacing system DLLs. Personally, I'd prefer it was bundled with MTA to prevent possible false positives with the anti-cheat or worse: a vulnerability via malicious dsound.dll.

Describe alternatives you've considered

I've already tried replacing the system DLLs, which works, as shown in this video: https://www.youtube.com/watch?v=xxY_xaFrYm4

Lots of Melons + Dumpster

It works fine so far both offline and online, but it's not something I would recommend anyone who's not familiar with this stuff.

Additional context

  • There's a small oversight in even base San Andreas with a Creative sound card on Windows XP where the Y axis is inverted (sounds above sound like they're below and viceversa), but it can be fixed in recent DSOAL by setting reverse-y = true in the [game_compat] section of alsoft.ini.
  • In base San Andreas, using a wrapper can crash the game when getting on a motorcycle, unless Radio EQ is manually turned off and back in while in-game. However, I haven't noticed it happening in MTA.
  • San Andreas shipped with EAX Unified (eax.dll) 4.0.0.1, so you could consider updating it to 4.0.1.0 (perhaps there's a better source but that one's clean and works fine so far, tho I admit I don't know the changes from the previous version but I'd guess it fixes some minor issues)
  • I've attached the files I use, or you can follow these instructions to install from the official download location directly, or compile DSOAL (dsound.dll) and OpenAL Soft (dsoal-aldrv.dll), of course. MTA-DSOAL.zip

Security Policy

  • [x] I have read and understood the Security Policy and this issue is not about a cheat or security vulnerability.

ThreeDeeJay avatar Jul 27 '22 13:07 ThreeDeeJay

Sounds like a nice project for someone.

Can we confirm that the licensing of these proposed options are compatible with ours?

Would like to hear some comparisons as well if any are available.

patrikjuvonen avatar Jul 27 '22 17:07 patrikjuvonen

Can we confirm that the licensing of these proposed options are compatible with ours?

@patrikjuvonen I'm not an expert in licensing, but it would need DSOAL (the wrapper, licensed under LGPL) and OpenAL Soft (the renderer, licensed under GPL and BSD-3). AFAIK OpenAL Soft has the more limiting license, but a bunch of open source/free games like Sector's Edge include it.

Would like to hear some comparisons as well if any are available.

In the first minute here, you can hear a comparison between DirectSound (how it sounds by default, without wrappers) and DirectSound3D (how it sounds with DSOAL): https://www.youtube.com/watch?v=xxY_xaFrYm4

ThreeDeeJay avatar Jul 27 '22 22:07 ThreeDeeJay

By the way, I made some Github actions to compile and release DSOAL and OpenAL Soft binaries. It's already a pull request on the main repo and someone could grab the YAML from here and edit them, maybe DSOAL could be added as a submodule to automaticaly compile with MTA on every commit push, like I did with OpenAL Soft.

ThreeDeeJay avatar Jul 28 '22 11:07 ThreeDeeJay

I'm afraid there weren't redistributables after 4.001. 4.0.1.0 comes from F.E.A.R., or SW battlefront... I'm gonna guess in turn from whatever the latest official SDK was before the openal-only sweep.

mirh avatar Aug 19 '22 15:08 mirh

hi guys im new to github, thanks so much for these files by the way. I play Grand prix 4 and have copied the 2 dll's where the exe resides. I have found that if i play single player eax works great. But if i do lan multiplayer game with 2 pc's eax is not working so it's something to do with multiplayer, i thought i'd run this by you and see if there is anything i can do to get it to work it probably has something to do with multiplayer which is a bummer

gp4wonder avatar Oct 25 '23 00:10 gp4wonder

@gp4wonder Does multiplayer use a different executable, DLL path or working folder? You could check where it's loading dsound.dll from in multiplayer with API Monitor like this. And you can try copying the files into SysWOW64, but like I mentioned in the first post, that can cause issues with other apps so proceed at your own risk. Otherwise, it might just be the multiplayer mode/anticheat disabling the loading of third-party/blacklisted DLLs to prevent hacks.

ThreeDeeJay avatar Oct 25 '23 01:10 ThreeDeeJay

Hi ThreeDeeJay, wow thanks for the quick reply, no there is only one executable gp4.exe. I will try the API monitor. I just copied the dsoal-aldrv.dll file into SysWOW64, not dsound.dll

gp4wonder avatar Oct 25 '23 01:10 gp4wonder

dsound.dll is harder to replace because the original one is protected so to disable the protection you can google "Take ownership registry key" for a reg key that adds a Take ownership option to the right click menu so that you can rename/move the original and copy the DSOAL one.

ThreeDeeJay avatar Oct 25 '23 01:10 ThreeDeeJay

that tool is awesome, i just took screenshot multiplayer uses dplaysvr.exe which is in SysWOW64 folder, that exe is required for tcp/ip for gp4 dplaysvr

gp4wonder avatar Oct 25 '23 01:10 gp4wonder

Although that being the case GP4.exe pid:9656 shows that the two modules are loaded from the game folder

gp4wonder avatar Oct 25 '23 01:10 gp4wonder

dsounddll

gp4wonder avatar Oct 25 '23 01:10 gp4wonder

multiplayer uses dplaysvr.exe which is in SysWOW64 folder

Oh boy, guess that explains it, but it's also a really bad sign. It probably means the only way you'll get EAX/3D audio in multiplayer is by replacing the system dsound.dll, unless you can:

  • Force the game to load a copy of that exe from a different, non-protected working folder where you can install/load DSOAL DLLs from
  • Force that exe to load dsound.dll from a non-protected folder, like maybe just forcing it to use the Grand Prix 4/ folder so it behaves like GP4.exe. I know that running executables as admin tends to set the working folder to the system one instead of the executable's, but I don't think there are ways to make system executables use a different working folder, unless CDing into another directory in command line, but I think the game itself handles/changes thew working folder.

I'm not sure how one would go about doing either method, as they'd both probably need some Windows trick, game source code modification or a reverse-engineered hack. 🤔

ThreeDeeJay avatar Oct 25 '23 01:10 ThreeDeeJay

I did now copy them both to windows SysWOW64 folder, after taking ownership of the dsound.dll file eax is enabled ingame but issue remains

gp4wonder avatar Oct 25 '23 02:10 gp4wonder

So EAX is enabled but you hear no reverb/3D audio? You also need alsoft.ini if it doesn't already exist in %APPDATA% (C:\Users\YOURUSERNAME\AppData\Roaming) Also you might wanna try the dsound.dll registry patcher in case it can allow loading the DLLs from the game folder. EDIT: By the way, you might wanna join our Discord server to continue the discussion there to avoid too much off-topic discussion here 😅

ThreeDeeJay avatar Oct 25 '23 03:10 ThreeDeeJay

Hi ThreeDeeJay, thanks again yeh that's correct EAX is enabled in the game, if i play single player it works It's only what i do tcp\ip lan that it doesn't work, you have been a great help, given me things i haven't tried. I'll keep you posted if i get this going

gp4wonder avatar Oct 25 '23 10:10 gp4wonder

If you'd like to help be greatful, the game sin't that big and can be downloaded from here:- https://www.myabandonware.com/game/grand-prix-4-dwu

then install gpxpatch, from here https://www.sdidit.nl/ set the compatibility mode on gp4.exe to windowsxp2, and run the game from gpxpatch.exe

don't forget to install the eax dll's. this game is worth it, only one you can play with keyboard and wheel

gp4wonder avatar Oct 25 '23 10:10 gp4wonder

https://www.youtube.com/@GP4wonderGP4wonder I have 3 videos ive uploaded, this is single player mode which works

gp4wonder avatar Oct 25 '23 11:10 gp4wonder

... what in the absolute hell has GP4 to do with GTA? And what has the directplay server to do with graphics/audio rendering? I really really don't think that a component used all across dozens of games would handle anything but network stuff.

I know that running executables as admin tends to set the working folder to the system one instead of the executable's

First time I hear about this (even though there are exceptions for certain built-in applications)

I'm not sure how one would go about doing either method, as they'd both probably need some Windows trick, game source code modification or a reverse-engineered hack.

Be it as it may, it's pretty easy actually? Just hex edit dsound.dll inside the executable or its libraries to some other name (and if you find none, then they are probably using CLSID which means you can play with registry entries).

mirh avatar Oct 25 '23 12:10 mirh

Interesting stuff! But let’s keep this MTA related

Lpsd avatar Oct 25 '23 13:10 Lpsd