narzoul / DDrawCompat

DirectDraw and Direct3D 1-7 compatibility, performance and visual enhancements for Windows Vista, 7, 8, 10 and 11
BSD Zero Clause License
907 stars 69 forks source link

DDrawCompat has issues with Dark Secrets of Africa #130

Closed BEENNath58 closed 1 year ago

BEENNath58 commented 2 years ago

I am trying to run a game Dark Secrets of Africa (obtainable from myabandonware) and it seems to have problems running on certain machines. The issue is suspected to be caused by something relating to DirectX. The experiment was done with DDrawCompat and DxWnd. The results were this:

DDrawCompat (DDC) on Win10 - crashes DDC on Win11 - runs DDC on Win7 - crashes DxWnd on Win11 - crashes in fullscreen but runs windowed DxWnd on Win10 - crashes DxWnd on Win7 - crashes DxWnd on WinXP - crashes in fullscreen but runs windowed

Basically you have to look at DDC only, DxWnd was here for references only. DxWnd behaviour with the game is completely same as the Windows native DirectX if I disable DxWnd's DirectX component, showing the DirectX is the problem. Now only Windows XP and Windows 11 can run the game without any of DxWnd or DDC. But since I mainly use Windows 11 and Windows 7, the former can't play video and the latter can't run at all. The crashes happen with errors such as

  1. "The instruction xxxxxxxx referenced instruction at yyyyyyy. The memory could not be read from".
  2. "An privileged instruction was executed at aaaaaaaa".
  3. "An illegal instruction was executed at bbbbbbbb".

Hopefully you can see the problem and fix it.

narzoul commented 2 years ago

Please upload the debug logs for Win7 and Win10.

BEENNath58 commented 2 years ago

Here you go: win7.log win11.log

narzoul commented 2 years ago

I meant the debug logs using the ReleaseWithDebugLogs build in the debug zip file.

The win 7 logs look like they were taken from a VM, and I'm not aware of any VMs having stable WDDM drivers, so you probably won't get DDrawCompat working there.

BEENNath58 commented 2 years ago

I got the log from Windows 11. Here: DDrawCompat-game.log

BEENNath58 commented 2 years ago

And Windows 7: DDrawCompat-game.log

narzoul commented 2 years ago

The Win7 version is apparently crashing in a driver callback that isn't even hooked by DDC (except for the logging in the debug versions). I don't really want to investigate it further as in my experience WDDM drivers in VMs are just bad, and DDC isn't really intended for VMs anyway.

The Win11 version is setting 32 bit display mode instead of 16 bit for some reason, that appears to be the primary difference compared to mine and probably the main issue. Unless I'm missing something and there is a way to run the game with 32 bit colors? I'm also a bit confused because in your first post you wrote that Win11 runs fine with DDC.

BEENNath58 commented 2 years ago

The Win7 version is apparently crashing in a driver callback that isn't even hooked by DDC (except for the logging in the debug versions). I don't really want to investigate it further as in my experience WDDM drivers in VMs are just bad, and DDC isn't really intended for VMs anyway.

I think I will pass this, if there's difficulty there's not much advantage of doing it

The Win11 version is setting 32 bit display mode instead of 16 bit for some reason, that appears to be the primary difference compared to mine and probably the main issue.

With only DxWnd, a tweak "NO EXCLUSIVE COOP LEVEL" was able to run the game but there were problems, mainly the son window scaled wrongly, it was having a window but the scene was fullscreen, thus bringing problems such as mouse clicking on desktop and such.

I am pretty sure that's not the problem with DDC. Also if I hook both DxWnd and DDC together and use that tweak, it doesn't run, neither does forcing 16-bit color. Apparently from other feedbacks from SF, it seems they needed to set 16bpp color in DxWnd as well while I didn't have to. So how do I force 16bpp colors in DDC?

narzoul commented 2 years ago

You shouldn't have to force it. The game doesn't even enumerate supported display modes so I'm pretty sure it's just hardcoded to use 16 bit (but I'll try to debug it and confirm).

I think something else (DxWnd?) is forcing it to 32 bit colors. And sure enough I found this in your logs: 0afc 21:10:57.690 Hooking function: DefWindowProcA (C:\Windows\SYSTEM32\ntdll.dll+0x97f80 [e9,db,ee,d9,98] -> H:\Emulators\DxWnd\v2_05_83_fx3_build\dxwnd.dll+0x96e60 [8b,44,24,10,8b,4c,24,0c])

Please make sure nothing else is hooking the game and get the debug logs with just DDrawCompat.

BEENNath58 commented 2 years ago

Okay I seem to have found the problem, DxWnd was getting loaded with Window hook. Without it the game works almost fine, almost.

A problem has now emerged that when I click somewhere on the map to move the character, it is supposed to go to that place. However with DDC, it just moves one step forward, and doesn't reach there where I clicked to go. This also happened with DxWnd when Vsync was on, which fixed the flashing cursor.

narzoul commented 2 years ago

I guess it needs some kind of FPS limit. Simply turning Vsync on is not enough (besides it's on by default). At 60Hz, FlipInterval=2 (30 FPS) makes it better but still stops occasionally. FlipInterval=3 (20 FPS) seems smooth. I'll see what can be done for the next version...

BEENNath58 commented 2 years ago

I guess it needs some kind of FPS limit. Simply turning Vsync on is not enough (besides it's on by default). At 60Hz, FlipInterval=2 (30 FPS) makes it better but still stops occasionally. FlipInterval=3 (20 FPS) seems smooth. I'll see what can be done for the next version...

I tried DxWnd's frame limiters and they don't help. For example 60fps caps through Vsync or frame limiter didn't fix the flashing cursor, but the character moved as expected. However the asynchronous blitting mode fixed the frame limiter but it brought the character movement problem. This looks to be the same scenario as DDC.

narzoul commented 2 years ago

I think the game has some weird timing issue. It's buggy even in a WinXP WM. I guess the only reason it ever worked correctly was because CPUs were much slower when it was released.

Inserting ~20ms delay in each page flip seems to fix the movement problem. Not sure why it's needed, since the game limits its own frame rate anyway by busy waiting on QueryPerformanceCounter apparently. But I gave up trying to debug it further.

Here's a test version with 20ms delay: ddraw.zip (diff.txt compared to v0.3.1)

I guess I'll need some odd config option in a future release to apply this "fix".

BEENNath58 commented 2 years ago

I think the game has some weird timing issue. It's buggy even in a WinXP WM. I guess the only reason it ever worked correctly was because CPUs were much slower when it was released.

Inserting ~20ms delay in each page flip seems to fix the movement problem. Not sure why it's needed, since the game limits its own frame rate anyway by busy waiting on QueryPerformanceCounter apparently. But I gave up trying to debug it further.

Here's a test version with 20ms delay: ddraw.zip (diff.txt compared to v0.3.1)

I guess I'll need some odd config option in a future release to apply this "fix".

Yes this one works fine. There is no issues here.

narzoul commented 1 year ago

The FpsLimiter=flipend(15) setting seems to work ok for me in v0.4.0.