dxwrapper: Can't wrap custom d3d8.dll with d3d8to9
I’m trying to run a game with a d3d8.dll from an older Windows 10 version that fixes some lighting-related issues the game has with the default Windows 10 d3d8.dll. Additionally, I’d like to wrap the older d3d8.dll with d3d8to9 so I can enable AF and AA.
This is what I have in my game folder:
dxwrapper.dll
dxwrapper.ini with the following config:
[Compatibility]
D3d8to9 = 1
[d3d9]
AnisotropicFiltering = 16
AntiAliasing = 1
This file includes all the other values in the default dxwrapper.ini file, but those have not been changed from their defaults.
d3d8.dll from the Stub folder
d3d8.ini with the following config:
;; Config file for Stub to dxwrapper
[General]
RealDllPath = Custom\d3d8.dll
WrapperMode = d3d8.dll
StubOnly = 0
LoadFromMemory = 0
Custom\d3d8.dll. This is the custom d3d8.dll that I want to load instead of the default Windows 10 one.
With all these files and configs, d3d8to9 seems to load since the AF and AA are both working. However, it also seems the default Windows 10 d3d8.dll has loaded instead of the custom one, since the lighting bug is present in the game.
When I change D3d8to9 in dxwrapper.ini from 1 to 0, the exact opposite happens; the custom d3d8.dll loads, which has resulted in the lighting bug being gone, but obviously now d3d8to9 doesn’t load as there is no AF nor AA.
It seems like I can only get one or the other to work simultaneously, but I’d like d3d8to9 to wrap the custom d3d8.dll. Am I missing something or is it impossible to get the result I’m trying to achieve here?
I’m using DxWrapper v1.0.6542.21. (latest release)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 75 (35 by maintainers)
I wanted to do some more research and @elishacloud’s info regarding Direct3D8 being redirected to the Direct3D9 drivers after Windows update 19H1 gave me some clues as to where I could look.
First I should mention how Freelancer makes use of DirectX 8’s lights. Basically the game uses so-called Thorn scripts to specify what kind of lights should be used in a scene. Inherently these are just compressed Lua scripts. Here’s an example of how a light is set in one of the scripts that has been decompressed:
If you look closely at the parameters in the
lightpropsentry, you can see that they look very similar to the values in the D3D8LIGHT8 struct.A while ago I talked to another Freelancer modder about the lighting bug. After a small investigation they concluded the light type
L_SPOTbecame broken after the Windows update. So they “fixed” it by going into every Thorn script to change each light with the typeL_SPOTtoL_POINT. Internally this changes the DirectX 8 light type fromD3DLIGHT_SPOTtoD3DLIGHT_POINT. However, in my opinion this isn’t really a good solution because point lights behave very differently from spot lights.I really wanted to look for a better solution, and based on the clue regarding the redirection of Direct3D8 to the Direct3D9 drivers, I checked out the documentation for the lights from both DirectX 8 and DirectX 9. One thing that stood out to me right away was that the description for the members
Falloff,Theta, andPhisimply said “Not supported.” in the DirectX 8 documentation, whereas in the DirectX 9 documentation it seems these definitely are supported. In the light specifications from the Thorn scripts I noticed that the valuethetawas set despite it apparently not even being supported in DirectX 8.I wanted to find out whether or not the sudden support of the three values in DirectX 9 is the cause of the lighting bug. Though I did not know what the given light values for
FallofforPhiare since they are not specified in the light properties. Hence I decided to use @elishacloud’s DirectX-Wrappers project to intercept theIDirect3DDevice8::SetLightmethod so I could see what the values for each light are and what happens when they are modified.After some trial and error, I came up with this:
Using the d3d8 wrapper with this code in Freelancer completely rectifies the lighting bug. Basically I reduced the
FalloffandThetavalues for spot lights to make them appear less harsh. Furthermore, I set a minimumFalloffvalue to ensure the light edges/shadows look smoother.I should mention that I can’t confirm whether my suspicion about
Falloff,Theta, andPhinot working on DirectX 8 is true because I actually haven’t done any tests on an older Windows version. Also, with these updated values the lighting doesn’t look exactly the same as how it originally did on older Windows versions; in most scenes the light looks slightly dimmer. Maybe a better DirectX programmer can have a look at it one day. Here’s the source code for the implemented lighting bug fix as a proof of concept: https://github.com/BC46/freelancer-lighting-bug-fix.Before and after screenshots:

Great! Thanks for all your help here!
Ok, great. I’m going to keep the if statement because we don’t want to do anything if
Thetais larger thanPhi. I’m also not going to change theFalloffsince that is best left at it current value.Here is the final code I will use. I will make a pull request later in d3d8to9.
Here is an updated dxwrapper build with this fix in it: dxwrapper.zip
I also enabled the following:
Putting aside that this should all be easily readable in the offline docs shipped with the sdk, you are right that the windows CE version was different. https://web.archive.org/web/20040103201823/http://msdn.microsoft.com/archive/en-us/dx81_c/directx_cpp/GRAPHICS/Reference/CPP/D3D/Structures/d3dlight8.asp https://web.archive.org/web/20040806062027/http://msdn.microsoft.com/archive/en-us/directx9_c/directx/graphics/reference/d3d/structures/d3dlight9.asp https://web.archive.org/web/20040907224729/http://msdn.microsoft.com/archive/en-us/directx9_c/directx/graphics/reference/d3d/enums/d3dlighttype.asp
I wasn’t sure if I was supposed to do this since it’s a very specific issue. But I’ll do it, thanks for letting me know.