FunkyFr3sh / cnc-ddraw

GDI, OpenGL and Direct3D 9 re-implementation of the DirectDraw API for classic 2D games for better compatibility with Windows ME, 2000, XP, Vista, 7, 8, 10, 11, Wine (Linux/macOS/Android) and Virtual Machines
https://discord.gg/afWXJNDDF5
MIT License
2.29k stars 148 forks source link

Bad Mojo Redux #16

Closed legluondunet closed 5 years ago

legluondunet commented 5 years ago

Hello, do you know this great adventure game? It's impossible today to play this game in other resolution than 640x480 and actually the game is not cnc-ddraw compatible. Will you be interested to try to make this game cnc-ddraw compatible?

FunkyFr3sh commented 5 years ago

Well... If you could generate a log file and upload it here, maybe I can tell what's going on with it :)

You can use the old test build I gave you before: https://github.com/CnCNet/cnc-ddraw/issues/9#issuecomment-488805261

legluondunet commented 5 years ago

voilà:

cnc-ddraw.log

elishacloud commented 5 years ago

Since I happened to have a copy, I took a quick look at this game. It looks like there are two issues with this game:

The first issue is that this game has some kind of hook into ddraw. It seems to crash even with a basic ddraw wrapper like DirectX-Wrappers that does nothing. If I use a wrapper like DDrawCompat it works but not before it prompts several messages about not being able to create hooks:

BadMojoError

However, if I use a wrapper like dsound.dll and then hook the ddraw APIs it seems to work.

Secondly this game requires single process affinity.

I did not look in more detail, so there may be a way to over come these issues. However, here is a wrapper that will work. It, uses dsound.dll and hooks ddraw APIs and then converts them into Direct3D9: dxwrapper.zip

FunkyFr3sh commented 5 years ago

Oh, nice one @elishacloud ! I guess I won't be able to do much without having the game, seems to be a special case.

He's on wine BTW, I think he's creating wine wrappers. Not sure how well your Direct3D9 one is going to work for him (I had a lot problems with Direct3D9 on wine...), OpenGL is usually a better choice, but it's worth a try I guess.

elishacloud commented 5 years ago

Yeah, Wine support with dxwrapper has been a bit sketchy. Some games work fine using dxwrapper with Wine and some don't. I have not looked into it much to see why. Unfortunately dxwrapper only supports Direct3D9. I have no plans to add support for OpenGL.

legluondunet commented 5 years ago

Hello @elishacloud , happy to see you again, I just tried dxwrapper, it's the first wrapper that didn't crash the game but...the game screen stay to 640x480 resolution on Wine.

It's off topic but do you think to add Vulkan support? It's today a more portable graphic library than directx isn't it?

elishacloud commented 5 years ago

Hello @legluondunet, I'm glad you were able to get dxwrapper working in Wine! I am not sure about the 640x480 issue. You could try enabling the DdrawUseNativeResolution option.

I currently don't plan to support Vulkan at this point. I chose to use Direct3D9 because it has the same architecture as DirectDraw/Direct3D 1-7. Starting with DirectX10 the architecture changed significantly. My goal is to convert all DirectDraw/Direct3D APIs to Direct3D9 so that any ddraw game will work with Direct3D9.

As far as using Vulkan, there are others who are building conversion from Direct3D9 to Vulkan. Check out the d9vk project. You could also check out dxup which converts Direct3D9 and Direct3D10 to Direct3D11.

elishacloud commented 5 years ago

I found a bit more information out about this. Even if you use a different wrapper, like dsound.dll and then hook the ddraw APIs this will only work if you hook them after the Bad Mojo executable has already hooked them.

Dsound is loaded later, which is why it works. If you use winmm then the same issue happens as using ddraw because winmm is loaded immediately at process launch.

Fixing this may require adding a feature to delay the hooking of the APIs, similar to what is already in the Ultimate-ASI-Loader.

legluondunet commented 5 years ago

Very interesting, it's a good track, thanks @elishacloud , I will take a look and make some tests.