elishacloud / dxwrapper

Fixes compatibility issues with older games running on Windows 10/11 by wrapping DirectX dlls. Also allows loading custom libraries with the file extension .asi into game processes.
zlib License
1.17k stars 83 forks source link

Only 1 screen resolution is available in Empire Earth II with dxwrapper. #38

Closed HerMajestyDrMona closed 4 years ago

HerMajestyDrMona commented 4 years ago

Hi Elisha. As first, thank you for your work on dxwrapper and contribution to d3d8to9 development. I'm creator of Unofficial Patch 1.5 for Empire Earth II: https://www.ee2.eu/patch/ I'm using a modified version of crosire's d3d8to9 to fix game problems and support DX9.

I knew that dxwrapper existed for quite a long time, but I never had a chance to test it. Today, I wanted to try something new, especially after seeing:

Adding AntiAliasing support into DirectX 8 or 9 games even if the game does not support it (Windows 10 only)

After starting the game with dxwrapper, I came to an issue where screen resolutions are not displayed on the list: https://i.imgur.com/diqvAMe.png

(for comparation): https://i.imgur.com/lZ64jBK.jpg

I tried modifying "dxwrapper.ini" with different settings, but nothing helped to display screen resolutions.

I came to a conclusion that dxwrapper might have too many fixes which are not needed for this game to work on Windows 10. Do you know if I can modify d3d8to9 in any easy way to enable AntiAliasing, or this would rather require to load much more libraries? Also, do you think AntiAliasing could cause some performance degradation, or it shouldn't matter that much? (This game already is horribly optimized).

Greetings.

EDIT: Sorry, it seems like DxWnd was the issue. After removing it's .dll file from game folder, dxwrapper starts with all resolutions :)

elishacloud commented 4 years ago

Do you know if I can modify d3d8to9 in any easy way to enable AntiAliasing, or this would rather require to load much more libraries?

Yes, this can be done. In fact, I created a branch for this and implemented it in d3d8to9. See my check-in here. I also created a release build for this: d3d8.zip

Also, do you think AntiAliasing could cause some performance degradation, or it shouldn't matter that much?

Yes, AntiAliasing will require more work on your GPU. So if your GPU is not fast enough it could cause performance degradation.

Sorry, it seems like DxWnd was the issue. After removing it's .dll file from game folder, dxwrapper starts with all resolutions :)

Yes, dxwrapper loads DxWnd.dll by default. Maybe this should not be enabled by default. Anyways you can disable this by adding this line to the dxwrapper ini file:

DxWnd = 0
HerMajestyDrMona commented 4 years ago

Wow, thank you so much. I tried to "import" it yesterday (and failed). You basically made the full work for me... Can't wait to test it when I'm back on computer.

I got a question: since it's supposed to only work on Windows 10, does dx8to9 detect it and simply ignores AntiAliasing in that function with "for loop min(16)"? Of course I'll test it too before release, it's easier easier to confirm with you when you have so much knowledge about it. After all I'll add a configuration switch too, to only enable it for players who need it.

elishacloud commented 4 years ago

I got a question: since it's supposed to only work on Windows 10, does dx8to9 detect it and simply ignores AntiAliasing in that function with "for loop min(16)"?

No. It does not detect Windows 10 and disable. I only tested my AntiAliasing feature once on Windows 7 and it did not work (no idea why though). Since, I don't have a Windows 7 system anymore so I cannot confirm if it always fails or it was just that one test. Dxwrapper is primarily targeting Windows 10 so I did not want to spend any time on it. In theory, the code should work on any OS, but it is untested.

The loop from 16 down is testing each AntiAliasing mode. 16 is the highest, though most GPUs can only support 8 or less. This code will enable the highest AntiAliasing mode supported by the video card.

Note: I would recommend doing some thorough tests with the game using AntiAliasing. AntiAliasing requires disabling backbuffer surface locking (see here). Backbuffer locking is not supported with AntiAliasing. If the game uses backbuffer locking anywhere it will break that part of the game, either by crashing or by objects disappearing.

HerMajestyDrMona commented 4 years ago

Thank you for explanation. I did first tests and it works pretty good. The quality improvement is very visible in this game. For now I didn't notice any graphics bugs caused by disabled backbuffer surface. I will make some more tests on different Windows versions and RTX2070 in the next few days. I'll let you know if Antialiasing worked there.

Thank you once again.

HerMajestyDrMona commented 4 years ago

Hello again @elishacloud I tested https://github.com/elishacloud/d3d8to9/commit/b5d10a8b09a2e460e54c3c84fb587fbc47690a91 on Windows 8.1 (using the same laptop) and it works fine.

However, there is a strange issue (which I detected earlier) with the normal dxwrapper. The log is fine:

18680 18:06:13.955 Starting D3d8to9 v1.9.2.0
18680 18:06:13.955 Redirecting 'Direct3DCreate8' to --> 'Direct3DCreate9' (220)
18680 18:06:13.955 Redirecting 'Direct3DCreate9' ...
18680 18:06:13.959 Loading d3dx9_xx.dll
18680 18:06:14.058 Loaded library: d3dx9_43.dll
18680 18:06:14.077 Redirecting 'Direct3DCreate8' to --> 'Direct3DCreate9' (220)
18680 18:06:14.077 Redirecting 'Direct3DCreate9' ...
18680 18:06:14.133 Setting MultiSample 8 Quality 0
18680 18:06:56.536 Quiting DxWrapper
18680 18:06:56.536 Unloading libraries...
18680 18:06:56.536 Reseting screen resolution
18680 18:06:56.560 Reseting font smoothing
18680 18:06:56.563 DxWrapper terminated!

However, whenever I alt+TAB (or ALT+ENTER to switch to/from Windowed mode) it seems like AntiAliasing disables itself.

I test it by loading the same game save and observing a building texture. When it disables itself the building becomes "sharp" as without AntiAliasing. This bug doesn't persist on the modified version of d3d8to9 with enabled AntiAliasing, which you sent me earlier today. It's not a big deal for this game, since I will use the modified d3d8to9, but I thought it's good to let you know about it.

elishacloud commented 4 years ago

Yeah, there are a couple issues with dxwrapper here. I added AntiAliasing support a long time ago and have made a lot of changes since then. I need to go back and put in a few more fixes in. Recently I've mostly been focusing on Silent Hill 2 and dd7to9, both of which have taken a lot of time from me.

HerMajestyDrMona commented 4 years ago

Oh Lord, those Silent Hill 2 edits are huge!

I just finished adding the Anti-Aliasing option to UP1.5 Settings: https://i.imgur.com/SfkGqHw.png

Too bad this game runs on a single core. A lot of people have performance issues :(

Can't wait to test AntiAliasing on my RTX 2070.

Thanks again for help.

elishacloud commented 4 years ago

I just finished adding the Anti-Aliasing option to UP1.5 Settings

Looks great!

Too bad this game runs on a single core. A lot of people have performance issues :(

AntiAliasing is primarily done by the GPU. It should not take additional CPU time. So if the game it CPU bound then enabling AntiAliasing might not have an effect on that.

HerMajestyDrMona commented 4 years ago

So if the game it CPU bound then enabling AntiAliasing might not have an effect on that.

I confirm that. Just tested on my new PC and the performance remains the same (this GPU was never fully used on that game). However, talking about the performance, in general d3d8to9 helped a lot (a bit higher FPS), so it's good how things are currently going :)

HerMajestyDrMona commented 4 years ago

Ok, this is funny. Probably unrelated to d3d8to9, but I'm getting crazy by 1 issue:

  1. Problem occurs only on my laptop with Intel HD GPU. On a PC with NVIDIA it works fine. Tested on 2 OS (Win 10 and "fresh" 8.1).
  2. Whenever antialiasing is enabled, and the game is in the full-screen mode, the PrtScr key doesn't work, so can't save screenshots (built-in game function). When I switch to the windowed mode (ALT+ENTER) - it works.
  3. When antialiasing is disabled - it starts working normally.
  4. After few hours of... assembling I went to game Settings -> Hotkeys remapping, and I noticed that the game doesn't detect PrtScr key press... So I changed the "save screenshot" hotkey to F12, and then screenshoting works normally.

Do you have any thoughts what could be the problem? It's really crazy how always 1 minor issue must exist.

EDIT: Found a temporary solution for myself... I used program "SharpKeys" to remap my "\" key (which in this laptop is placed on the right, (next to the space). It is identified as: "Special: ISO extra key (00_56)". Changing it to "Special: Right Alt (E0_38)" or "Special: Alt Gr (E0_2038)" allows me to use this key + PrtScr to make a screenshot. However, using the normal Right Alt (which is next to it) doesn't trigger it... I guess I'll just stop thinking about it until someone else reports the same issue.

elishacloud commented 4 years ago

However, whenever I alt+TAB (or ALT+ENTER to switch to/from Windowed mode) it seems like AntiAliasing disables itself.

This should be fixed in the latest build. You can test it with this download: dxwrapper.zip

Whenever antialiasing is enabled, and the game is in the full-screen mode, the PrtScr key doesn't work ... Do you have any thoughts what could be the problem?

No, this is a weird issue. However, I know that there are rules for when screenshots can be taken with antialiasing enabled. If you check out this page under the remarks section it says This method is the only way to capture an antialiased screen shot. Is it possible that your laptop detects antialiasing and disables the PrtScr key to avoid some kind of issue?

HerMajestyDrMona commented 4 years ago

This should be fixed in the latest build.

Sorry, in dxwrapper AntiAliasing still disables itself. After game launch (Anti-Aliasing works): https://i.imgur.com/pRRLTdZ.jpg Windowed mode (ALT+ENTER): https://i.imgur.com/tSk8ICq.jpg Afrer switching back to full screen: https://i.imgur.com/KcGtHQc.jpg Log: https://pastebin.com/raw/XfDwSb2K

But please don't worry about it. The current version of d3d8to9 with AntiAliasing is more than enough for EE2. If this problem doesn't occur on the other games, then I think it's not worth your time.

If you check out this page under the remarks section it says Thanks, I'll read a little bit more about it later, and check if game uses the similar function calls.

Is it possible that your laptop detects antialiasing and disables the PrtScr key to avoid some kind of issue?

Today, someone else reported this problem to me, so it's not only my laptop. His laptop has 2 GPUs, and the game is running on Nvidia. So for me it seems like OS decides to disable PrtScr key. This is very strange, because changing the hotkey to something else (Scroll Lock) works just fine (and takes screenshots with AntiAliasing visible). I also downloaded some "KeyboardTest" software, and seems like it doesn't detect PrtScr press, but on this page it works: https://www.keyboardtester.com/tester.html

I also tried to intercept the key press in the launcher program (which anyway runs in the background). The PrtScr press was detected correctly, but then when I tried simulate the "working" combination with keybd_event - it didn't seem to work the same way as I've done remapping with "SharpKeys". A very confusing thing.

EDIT: OMG, this is crazy. I just changed PrtScr to Scroll Lock in "SharpKeys". And guess what? The game reads PrtScr now normally (to take a screenshot). When I'm remapping it (in game settings) and clicking PrtScn it shows PrtScn instead of Scroll Lock. Something funny is going on on Windows to have so dynamic behavior.

elishacloud commented 4 years ago

Sorry, in dxwrapper AntiAliasing still disables itself.

There is definitely some generic issues here. Looks like I forgot to set the render state after resetting the device. Try this one: dxwrapper.zip

I'm not really sure what the issue is with PrtScr. I've never really looked into an issue like that before.

HerMajestyDrMona commented 4 years ago

Sorry, still the same problem. AA disables itself.

I'm not really sure what the issue is with PrtScr. I've never really looked into an issue like that before.

Yes, sorry. I was just sharing thoughts to free my brain from solutions I already tried. I'm going the hardcore way now. Additional, new hotkey (Scroll Lock) for screenshoting + the launcher program will simulate Scroll Lock press on Prt Scr press...

elishacloud commented 4 years ago

I made a few minor changes in the AA support in d3d8to9 branch to remove some unneeded items. You can see my changes here: 1077d80

Sorry, still the same problem. AA disables itself.

Ok, I finally fixed this. I tested it with Serious Sam The First Encounter so it should work with Empire Earth II. I was unable to get Empire Earth II to go into fullscreen mode natively so I could not test it with Empire Earth II.

Updated dll: dxwrapper.zip

I'm going the hardcore way now. Additional, new hotkey (Scroll Lock) for screenshoting + the launcher program will simulate Scroll Lock press on Prt Scr press...

Interesting work around. Just keep in mind that some people use KVMs and some KVMs use Scroll Lock to switch systems.

HerMajestyDrMona commented 4 years ago

Ok, I finally fixed this. I tested it with Serious Sam The First Encounter so it should work with Empire Earth II. I was unable to get Empire Earth II to go into fullscreen mode natively so I could not test it with Empire Earth II.

Thanks! Seems to work now after ALT+TAB :) For EE2 (I don't it will ever be needed to test again), but the only possibility to play in Full Screen on Win 8 / 8.1 / 10 is using Unofficial Patch 1.5: https://ee2.eu/patch. It has some fixes in executables applied by assembly, so not easy to move it to "native" game. There is also a minimal version with no installer, which only fixes compatibility issues (and is designed for "other mods"): https://www.ee2.eu/patch/developers/ - so this one is the best to test in the "vanilla" form.

Interesting work around. Just keep in mind that some people use KVMs and some KVMs use Scroll Lock to switch systems.

The old hotkey works together with the new one, and the "workaround" can be disabled as well. After all the game allows to modify hotkeys yourself, so in those rare cases PrtScn/ScrlLck can be changed to something else. I wanted to have it working "out of box", because there are people from 170 countries (based on last 365 days) playing this game. Most of them don't understand English well to read help pages.

elishacloud commented 4 years ago

For EE2 (I don't it will ever be needed to test again), but the only possibility to play in Full Screen on Win 8 / 8.1 / 10 is using Unofficial Patch 1.5: https://ee2.eu/patch.

Ok, thanks!

It has some fixes in executables applied by assembly, so not easy to move it to "native" game.

Yeah, we had the same issue with Silent Hill 2. However, I wanted to make sure that the project could work with just one dll and one ini file so I moved the assembly into the cpp files. See here for an example. Not easy to implement, but I prefer it to modifying the executable.

The old hotkey works together with the new one, and the "workaround" can be disabled as well. After all the game allows to modify hotkeys yourself, so in those rare cases PrtScn/ScrlLck can be changed to something else.

Yep, probably not an issue for most systems.

I wanted to have it working "out of box", because there are people from 170 countries (based on last 365 days) playing this game. Most of them don't understand English well to read help pages.

Nice. Empire Earth was a pretty popular game. I had friends that used to play it when I was younger!

Anyways, it looks like everything in this issue is resolved so it can probably be closed now. Thanks!

elishacloud commented 4 years ago

@HerMajestyDrMona, I was browsing around the Direct3D9 documentation and found some option about the PrtScr button. You can see the documentation here. Check out the D3DCREATE_DISABLE_PRINTSCREEN option. This option is only supposed to work on Direct3D 9Ex, but it does seem like this is enabled for you on Empire Earth II. Anyways, just thought I would let you know what I found.

HerMajestyDrMona commented 4 years ago

Wow, very interesting! Thanks for sharing. I'll check it out later today.

HerMajestyDrMona commented 4 years ago

@elishacloud thank you for provided documentation. I'm not sure where should I add: &= ~D3DCREATE_DISABLE_PRINTSCREEN;

I tried at the end of "ConvertPresentParameters":

Output.Flags &= ~D3DCREATE_DISABLE_PRINTSCREEN;

and "UpdatePresentParameterForMultisample":

pPresentationParameters->Flags &= ~D3DCREATE_DISABLE_PRINTSCREEN;

But I guess those are wrong places. Do you maybe know where exactly should I put it to test?

elishacloud commented 4 years ago

This is actually a CreateDevice parameter. My suggestion would be to add a line somewhere around here that looks like this:

BehaviorFlags &= ~D3DCREATE_DISABLE_PRINTSCREEN;
HerMajestyDrMona commented 4 years ago

Thank you. How funny, yesterday I also edited "BehaviorFlags" at the recommended place, and also right before "CreateDevice" calls. It seems to not change anything (Prt Scn doesn't work). I think it's some bug in Windows / drivers, since it doesn't happen on my other PC. This flag must be inserted at some higher level. Still, good that we tested it and at least we know that such "features" exist in DirectX.

HerMajestyDrMona commented 2 years ago

Dear @elishacloud. I hope it's not a problem that I refreshed this issue. I have got a simple question related to d3d8to9 with antialiasing. Would your please find some time to check it?

Generally, I detected that sometimes the game freezes after ALT+TAB. I was searching for the root cause of this problem for few years, but since it was hard to reproduce I did not focus on it that much.

Finally, I found the reason of the freeze, and it seem to be there:

Digging

Digging2

Do you have any idea what could go wrong here? I'm generally asking for some tips what to check, or maybe you've seen the similar issue before?

Again thanks for your help with antialiasing. Our community really enjoyed it for the past years.

EDIT: It also seem to happen when Antialiasing is disabled. Always function ProxyInterface->Reset(&PresentParams) takes 40 seconds to finish. Do you maybe know some parameter that would decide about the timeout?

EDIT: Problem seems to be solved with option "Disable fullscreen optimizations"... Sorry for bothering you with this issue. I posted details here: https://github.com/crosire/d3d8to9/issues/133