narzoul / DDrawCompat

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

Tzar: Burden of the Crown rendering issue #210

Closed argoneuscze closed 1 year ago

argoneuscze commented 1 year ago

Hello,

I'm trying to get this game working in proper (borderless) fullscreen (1440p 165hz monitor), ie. no black borders and such.

I have used a 3rd party HD patch which lets the game run at 1080p, but on my monitor that's unfortunately only a small part of my screen, and the game just shows up in a small box.

I have used your fix on top of that to improve the DDraw experience and it works amazing at first glance - game is properly fullscreened and upscaled, alttabbing is instant etc., there's just a rendering issue.

tzar1 This is what it looks like after loading a map - everything looks just fine.

But then if I scroll to the right, top or bottom specifically (scrolling to the left works fine), I get this: tzar2 It actually extends a little bit more on my screen, but the screenshot seems to "fix" a part of it.

The "glitched" area is always this "box" on the right, I'm thinking it's some strange interaction between the HD patch which lets the game run widescreen (as it natively only supports 1024x768) and your patch, like the game only knows to render the regular viewport and doesn't properly adjust for widescreen.

I'm on Windows 10, using a RTX 3070Ti with latest drivers, if that helps.

I know next to nothing about how these older games or the HD patches and whatnot work, would you please happen to have any idea of what could be done to fix it? It would be basically perfect if this worked. Thanks a ton!

argoneuscze commented 1 year ago

I just tried it without the HD patch, just vanilla GOG install - and it doesn't seem to get picked up by DDrawCompat at all without it :(

From what I find on the internet, it uses DirectDraw, version 7.0, so I think it should potentially work?

narzoul commented 1 year ago

It's lucky that the HD patch actually includes source code, so it wasn't too hard to figure it out.

It looks like the rendering glitch is not a bug in DDrawCompat. I suppose it's an artifact caused by having a higher viewing area than what the game expects. But strangely, if you press the ctrl key in game, it redraws the whole screen, which gets rid of the glitches. The TzarRunner program seems to abuse this to fix the glitches by repeatedly sending fake ctrl key presses to the Tzar window on a timer.

If you run the game without DDrawCompat directly through TzarHD.exe, you'll see that it works the same way as with DDrawCompat, and you can manually fix the screen glitches by pressing ctrl. Or, apparently TzarRunner also implements F12 as a hotkey to stop/start the redraw timer, so you can temporarily see the glitches while the timer is stopped.

TzarRunner basically launches TzarHD.exe, then calls WaitForInputIdle to wait for it to finish processing some initial inputs, then tries to find the handle of the Tzar window so it can send the fake ctrl keypresses to it.

I suppose the problem is that when DDrawCompat is used, it causes a delay in creating the Tzar window (because of all the initial hooks installed, I guess), so TzarRunner doesn't find the window and just exits. So the effect is the same as if you launched TzarHD directly (except it also enables some compatibility options, like 16-bit color mode).

Anyway, I replaced the WaitForInputIdle call with a simple Sleep(2000) call, which delays the window search by 2 seconds. This seems to fix the issue. Here's the patched version of the patch: TzarRunner.zip

argoneuscze commented 1 year ago

Oh, thank you so much! I'm honestly amazed you went so far just for a random game.

By the way, do you have any idea, why it doesn't work with the original game without the HD patch?

narzoul commented 1 year ago

I couldn't really test it without the HD patch, because the game just crashes most of the time at startup, with or without DDrawCompat. I get multiple access violations when running it through a debugger, but none of them seem to be ddraw related.

In the rare cases when it doesn't crash, I just get this error: tzar

I couldn't get past this, no matter what settings I use. Again, I get the same error without DDrawCompat. But DDrawCompat does get loaded, you can see that a log file is generated at least. Isn't that the case for you?

argoneuscze commented 1 year ago

Hmm, it works for me just fine - I run Setup.exe first as admin.

Either way, it seems like it hooks correctly when I set DIRECTXDEVICE=0 in tzar.ini - whatever that does; but TzarHD seems to do it too.

Now the only remaining problem is that OBS doesn't seem to be able to hook into the game, but that probably has nothing to do with DDrawCompat...

Thanks so very much for your help!

narzoul commented 1 year ago

Game Capture and Window Capture in OBS probably won't work, but Display Capture should.