1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Replace Ramp Emulation device with RGB Emulation

Fixes battle scenes in Star Wars Rebellion, apparently broken by a
Windows 10 update (issue #22).
Older versions of d3dim.dll still work correctly.
This commit is contained in:
narzoul 2020-04-05 21:09:44 +02:00
parent 13f3b0ced7
commit 3cc5a47156
6 changed files with 76 additions and 10 deletions

View File

@ -66,6 +66,7 @@ namespace DDraw
SET_COMPAT_METHOD(GetSurfaceDesc);
SET_COMPAT_METHOD(IsLost);
SET_COMPAT_METHOD(Lock);
SET_COMPAT_METHOD(QueryInterface);
SET_COMPAT_METHOD(ReleaseDC);
SET_COMPAT_METHOD(Restore);
SET_COMPAT_METHOD(SetPalette);

View File

@ -1,3 +1,5 @@
#include <d3d.h>
#include <Common/Log.h>
#include <DDraw/Log.h>
@ -51,3 +53,56 @@ std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC2& sd)
<< sd.ddsCaps
<< sd.dwTextureStage;
}
std::ostream& operator<<(std::ostream& os, const GUID& guid)
{
#define LOG_GUID(g) if (g == guid) return os << #g
LOG_GUID(CLSID_DirectDraw);
LOG_GUID(CLSID_DirectDraw7);
LOG_GUID(CLSID_DirectDrawClipper);
LOG_GUID(IID_IDirectDraw);
LOG_GUID(IID_IDirectDraw2);
LOG_GUID(IID_IDirectDraw4);
LOG_GUID(IID_IDirectDraw7);
LOG_GUID(IID_IDirectDrawSurface);
LOG_GUID(IID_IDirectDrawSurface2);
LOG_GUID(IID_IDirectDrawSurface3);
LOG_GUID(IID_IDirectDrawSurface4);
LOG_GUID(IID_IDirectDrawSurface7);
LOG_GUID(IID_IDirectDrawPalette);
LOG_GUID(IID_IDirectDrawClipper);
LOG_GUID(IID_IDirectDrawColorControl);
LOG_GUID(IID_IDirectDrawGammaControl);
LOG_GUID(IID_IDirect3D);
LOG_GUID(IID_IDirect3D2);
LOG_GUID(IID_IDirect3D3);
LOG_GUID(IID_IDirect3D7);
LOG_GUID(IID_IDirect3DRampDevice);
LOG_GUID(IID_IDirect3DRGBDevice);
LOG_GUID(IID_IDirect3DHALDevice);
LOG_GUID(IID_IDirect3DMMXDevice);
LOG_GUID(IID_IDirect3DRefDevice);
LOG_GUID(IID_IDirect3DNullDevice);
LOG_GUID(IID_IDirect3DTnLHalDevice);
LOG_GUID(IID_IDirect3DDevice);
LOG_GUID(IID_IDirect3DDevice2);
LOG_GUID(IID_IDirect3DDevice3);
LOG_GUID(IID_IDirect3DDevice7);
LOG_GUID(IID_IDirect3DTexture);
LOG_GUID(IID_IDirect3DTexture2);
LOG_GUID(IID_IDirect3DLight);
LOG_GUID(IID_IDirect3DMaterial);
LOG_GUID(IID_IDirect3DMaterial2);
LOG_GUID(IID_IDirect3DMaterial3);
LOG_GUID(IID_IDirect3DExecuteBuffer);
LOG_GUID(IID_IDirect3DViewport);
LOG_GUID(IID_IDirect3DViewport2);
LOG_GUID(IID_IDirect3DViewport3);
LOG_GUID(IID_IDirect3DVertexBuffer);
LOG_GUID(IID_IDirect3DVertexBuffer7);
#undef LOG_GUID
OLECHAR str[256] = {};
StringFromGUID2(guid, str, sizeof(str));
return os << str;
}

View File

@ -9,3 +9,4 @@ std::ostream& operator<<(std::ostream& os, const DDSCAPS2& caps);
std::ostream& operator<<(std::ostream& os, const DDPIXELFORMAT& pf);
std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC& sd);
std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC2& sd);
std::ostream& operator<<(std::ostream& os, const GUID& guid);

View File

@ -129,6 +129,12 @@ namespace DDraw
return result;
}
template <typename TSurface>
HRESULT SurfaceImpl<TSurface>::QueryInterface(TSurface* This, REFIID riid, LPVOID* obp)
{
return s_origVtable.QueryInterface(This, (IID_IDirect3DRampDevice == riid ? IID_IDirect3DRGBDevice : riid), obp);
}
template <typename TSurface>
HRESULT SurfaceImpl<TSurface>::ReleaseDC(TSurface* This, HDC hDC)
{

View File

@ -35,6 +35,7 @@ namespace DDraw
virtual HRESULT IsLost(TSurface* This);
virtual HRESULT Lock(TSurface* This, LPRECT lpDestRect, TSurfaceDesc* lpDDSurfaceDesc,
DWORD dwFlags, HANDLE hEvent);
virtual HRESULT QueryInterface(TSurface* This, REFIID riid, LPVOID* obp);
virtual HRESULT ReleaseDC(TSurface* This, HDC hDC);
virtual HRESULT Restore(TSurface* This);
virtual HRESULT SetPalette(TSurface* This, LPDIRECTDRAWPALETTE lpDDPalette);

View File

@ -14,17 +14,19 @@ namespace
void* userArg;
};
template <typename TDirect3d, typename TDirectDrawSurface, typename TDirect3dDevice, typename... Params>
HRESULT STDMETHODCALLTYPE createDevice(
IDirect3D7* This,
TDirect3d* This,
REFCLSID rclsid,
LPDIRECTDRAWSURFACE7 lpDDS,
LPDIRECT3DDEVICE7* lplpD3DDevice)
TDirectDrawSurface* lpDDS,
TDirect3dDevice** lplpD3DDevice,
Params... params)
{
HRESULT result = CompatVtable<IDirect3D7Vtbl>::s_origVtable.CreateDevice(
This, rclsid, lpDDS, lplpD3DDevice);
HRESULT result = CompatVtable<Vtable<TDirect3d>>::s_origVtable.CreateDevice(
This, (IID_IDirect3DRampDevice == rclsid) ? IID_IDirect3DRGBDevice : rclsid, lpDDS, lplpD3DDevice, params...);
if (SUCCEEDED(result))
{
CompatVtable<IDirect3DDevice7Vtbl>::hookVtable((*lplpD3DDevice)->lpVtbl);
CompatVtable<Vtable<TDirect3dDevice>>::hookVtable((*lplpD3DDevice)->lpVtbl);
}
return result;
}
@ -73,12 +75,12 @@ namespace
This, &d3dEnumDevicesCallback, &params);
}
template <typename TDirect3dVtbl>
void setCompatVtable7(TDirect3dVtbl& /*vtable*/)
void setCompatVtable2(IDirect3DVtbl& /*vtable*/)
{
}
void setCompatVtable7(IDirect3D7Vtbl& vtable)
template <typename TDirect3dVtbl>
void setCompatVtable2(TDirect3dVtbl& vtable)
{
vtable.CreateDevice = &createDevice;
}
@ -91,7 +93,7 @@ namespace Direct3d
{
vtable.EnumDevices = &enumDevices;
// No need to fix FindDevice since it uses EnumDevices
setCompatVtable7(vtable);
setCompatVtable2(vtable);
}
template Direct3d<IDirect3D>;