Skip to content

Commit

Permalink
Fix broken layout of virtual function tables when building with MinGW (
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalh authored Dec 30, 2020
1 parent 654588e commit 94bdd33
Show file tree
Hide file tree
Showing 16 changed files with 540 additions and 310 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ cmake_minimum_required(VERSION 3.12)
project(d3d8to9 CXX)

set(SRCS
source/d3d8to9_base.cpp
source/d3d8.hpp
source/d3d8to9.cpp
source/d3d8to9_device.cpp
source/d3d8to9.hpp
source/d3d8to9_base.cpp
source/d3d8to9_device.cpp
source/d3d8to9_index_buffer.cpp
source/d3d8to9_surface.cpp
source/d3d8to9_swap_chain.cpp
Expand Down
1 change: 1 addition & 0 deletions d3d8to9.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="res\resource.h" />
<ClInclude Include="source\d3d8.hpp" />
<ClInclude Include="source\d3d8to9.hpp" />
<ClInclude Include="source\d3d8types.hpp" />
<ClInclude Include="source\d3dx9.hpp" />
Expand Down
3 changes: 3 additions & 0 deletions d3d8to9.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<ClInclude Include="res\resource.h">
<Filter>resources</Filter>
</ClInclude>
<ClInclude Include="source\d3d8.hpp">
<Filter>helpers</Filter>
</ClInclude>
<ClInclude Include="source\d3d8to9.hpp" />
<ClInclude Include="source\d3d8types.hpp">
<Filter>helpers</Filter>
Expand Down
254 changes: 254 additions & 0 deletions source/d3d8.hpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion source/d3d8to9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PFN_D3DXLoadSurfaceFromSurface D3DXLoadSurfaceFromSurface = nullptr;
std::ofstream LOG;
#endif

extern "C" Direct3D8 *WINAPI Direct3DCreate8(UINT SDKVersion)
extern "C" IDirect3D8 *WINAPI Direct3DCreate8(UINT SDKVersion)
{
#ifndef D3D8TO9NOLOG
static bool LogMessageFlag = true;
Expand Down
374 changes: 162 additions & 212 deletions source/d3d8to9.hpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions source/d3d8to9_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ HRESULT STDMETHODCALLTYPE Direct3D8::QueryInterface(REFIID riid, void **ppvObj)
if (ppvObj == nullptr)
return E_POINTER;

if (riid == __uuidof(this) ||
if (riid == __uuidof(IDirect3D8) ||
riid == __uuidof(IUnknown))
{
AddRef();
*ppvObj = this;
*ppvObj = static_cast<IDirect3D8 *>(this);

return S_OK;
}
Expand Down Expand Up @@ -166,7 +166,7 @@ HMONITOR STDMETHODCALLTYPE Direct3D8::GetAdapterMonitor(UINT Adapter)
{
return ProxyInterface->GetAdapterMonitor(Adapter);
}
HRESULT STDMETHODCALLTYPE Direct3D8::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS8 *pPresentationParameters, Direct3DDevice8 **ppReturnedDeviceInterface)
HRESULT STDMETHODCALLTYPE Direct3D8::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS8 *pPresentationParameters, IDirect3DDevice8 **ppReturnedDeviceInterface)
{
#ifndef D3D8TO9NOLOG
LOG << "Redirecting '" << "IDirect3D8::CreateDevice" << "(" << this << ", " << Adapter << ", " << DeviceType << ", " << hFocusWindow << ", " << BehaviorFlags << ", " << pPresentationParameters << ", " << ppReturnedDeviceInterface << ")' ..." << std::endl;
Expand Down
94 changes: 52 additions & 42 deletions source/d3d8to9_device.cpp

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions source/d3d8to9_index_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::QueryInterface(REFIID riid, void
if (ppvObj == nullptr)
return E_POINTER;

if (riid == __uuidof(this) ||
if (riid == __uuidof(IDirect3DIndexBuffer8) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(Direct3DResource8))
riid == __uuidof(IDirect3DResource8))
{
AddRef();
*ppvObj = this;
*ppvObj = static_cast<IDirect3DIndexBuffer8 *>(this);

return S_OK;
}
Expand All @@ -44,7 +44,7 @@ ULONG STDMETHODCALLTYPE Direct3DIndexBuffer8::Release()
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::GetDevice(Direct3DDevice8 **ppDevice)
HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Expand Down
6 changes: 3 additions & 3 deletions source/d3d8to9_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ HRESULT STDMETHODCALLTYPE Direct3DSurface8::QueryInterface(REFIID riid, void **p
if (ppvObj == nullptr)
return E_POINTER;

if (riid == __uuidof(this) ||
if (riid == __uuidof(IDirect3DSurface8) ||
riid == __uuidof(IUnknown))
{
AddRef();
*ppvObj = this;
*ppvObj = static_cast<IDirect3DSurface8 *>(this);

return S_OK;
}
Expand All @@ -43,7 +43,7 @@ ULONG STDMETHODCALLTYPE Direct3DSurface8::Release()
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DSurface8::GetDevice(Direct3DDevice8 **ppDevice)
HRESULT STDMETHODCALLTYPE Direct3DSurface8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Expand Down
6 changes: 3 additions & 3 deletions source/d3d8to9_swap_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ HRESULT STDMETHODCALLTYPE Direct3DSwapChain8::QueryInterface(REFIID riid, void *
if (ppvObj == nullptr)
return E_POINTER;

if (riid == __uuidof(this) ||
if (riid == __uuidof(IDirect3DSwapChain8) ||
riid == __uuidof(IUnknown))
{
AddRef();
*ppvObj = this;
*ppvObj = static_cast<IDirect3DSwapChain8 *>(this);

return S_OK;
}
Expand All @@ -49,7 +49,7 @@ HRESULT STDMETHODCALLTYPE Direct3DSwapChain8::Present(const RECT *pSourceRect, c

return ProxyInterface->Present(pSourceRect, pDestRect, hDestWindowOverride, nullptr, 0);
}
HRESULT STDMETHODCALLTYPE Direct3DSwapChain8::GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, Direct3DSurface8 **ppBackBuffer)
HRESULT STDMETHODCALLTYPE Direct3DSwapChain8::GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer)
{
if (ppBackBuffer == nullptr)
return D3DERR_INVALIDCALL;
Expand Down
36 changes: 18 additions & 18 deletions source/d3d8to9_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ HRESULT STDMETHODCALLTYPE Direct3DTexture8::QueryInterface(REFIID riid, void **p
if (ppvObj == nullptr)
return E_POINTER;

if (riid == __uuidof(this) ||
if (riid == __uuidof(IDirect3DTexture8) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(Direct3DResource8) ||
riid == __uuidof(Direct3DBaseTexture8))
riid == __uuidof(IDirect3DResource8) ||
riid == __uuidof(IDirect3DBaseTexture8))
{
AddRef();
*ppvObj = this;
*ppvObj = static_cast<IDirect3DTexture8 *>(this);

return S_OK;
}
Expand All @@ -45,7 +45,7 @@ ULONG STDMETHODCALLTYPE Direct3DTexture8::Release()
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetDevice(Direct3DDevice8 **ppDevice)
HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Expand Down Expand Up @@ -112,7 +112,7 @@ HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetLevelDesc(UINT Level, D3DSURFACE_

return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetSurfaceLevel(UINT Level, Direct3DSurface8 **ppSurfaceLevel)
HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetSurfaceLevel(UINT Level, IDirect3DSurface8 **ppSurfaceLevel)
{
if (ppSurfaceLevel == nullptr)
return D3DERR_INVALIDCALL;
Expand Down Expand Up @@ -157,13 +157,13 @@ HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::QueryInterface(REFIID riid, void
if (ppvObj == nullptr)
return E_POINTER;

if (riid == __uuidof(this) ||
if (riid == __uuidof(IDirect3DCubeTexture8) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(Direct3DResource8) ||
riid == __uuidof(Direct3DBaseTexture8))
riid == __uuidof(IDirect3DResource8) ||
riid == __uuidof(IDirect3DBaseTexture8))
{
AddRef();
*ppvObj = this;
*ppvObj = static_cast<IDirect3DCubeTexture8 *>(this);

return S_OK;
}
Expand All @@ -183,7 +183,7 @@ ULONG STDMETHODCALLTYPE Direct3DCubeTexture8::Release()
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetDevice(Direct3DDevice8 **ppDevice)
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Expand Down Expand Up @@ -250,7 +250,7 @@ HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetLevelDesc(UINT Level, D3DSURF

return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, Direct3DSurface8 **ppCubeMapSurface)
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8 **ppCubeMapSurface)
{
if (ppCubeMapSurface == nullptr)
return D3DERR_INVALIDCALL;
Expand Down Expand Up @@ -295,13 +295,13 @@ HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::QueryInterface(REFIID riid, vo
if (ppvObj == nullptr)
return E_POINTER;

if (riid == __uuidof(this) ||
if (riid == __uuidof(IDirect3DVolumeTexture8) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(Direct3DResource8) ||
riid == __uuidof(Direct3DBaseTexture8))
riid == __uuidof(IDirect3DResource8) ||
riid == __uuidof(IDirect3DBaseTexture8))
{
AddRef();
*ppvObj = this;
*ppvObj = static_cast<IDirect3DVolumeTexture8 *>(this);

return S_OK;
}
Expand All @@ -321,7 +321,7 @@ ULONG STDMETHODCALLTYPE Direct3DVolumeTexture8::Release()
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetDevice(Direct3DDevice8 **ppDevice)
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Expand Down Expand Up @@ -388,7 +388,7 @@ HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetLevelDesc(UINT Level, D3DVO

return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetVolumeLevel(UINT Level, Direct3DVolume8 **ppVolumeLevel)
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetVolumeLevel(UINT Level, IDirect3DVolume8 **ppVolumeLevel)
{
if (ppVolumeLevel == nullptr)
return D3DERR_INVALIDCALL;
Expand Down
8 changes: 4 additions & 4 deletions source/d3d8to9_vertex_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::QueryInterface(REFIID riid, voi
if (ppvObj == nullptr)
return E_POINTER;

if (riid == __uuidof(this) ||
if (riid == __uuidof(IDirect3DVertexBuffer8) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(Direct3DResource8))
riid == __uuidof(IDirect3DResource8))
{
AddRef();
*ppvObj = this;
*ppvObj = static_cast<IDirect3DVertexBuffer8 *>(this);

return S_OK;
}
Expand All @@ -44,7 +44,7 @@ ULONG STDMETHODCALLTYPE Direct3DVertexBuffer8::Release()
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::GetDevice(Direct3DDevice8 **ppDevice)
HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Expand Down
6 changes: 3 additions & 3 deletions source/d3d8to9_volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ HRESULT STDMETHODCALLTYPE Direct3DVolume8::QueryInterface(REFIID riid, void **pp
if (ppvObj == nullptr)
return E_POINTER;

if (riid == __uuidof(this) ||
if (riid == __uuidof(IDirect3DVolume8) ||
riid == __uuidof(IUnknown))
{
AddRef();
*ppvObj = this;
*ppvObj = static_cast<IDirect3DVolume8 *>(this);

return S_OK;
}
Expand All @@ -43,7 +43,7 @@ ULONG STDMETHODCALLTYPE Direct3DVolume8::Release()
return ProxyInterface->Release();
}

HRESULT STDMETHODCALLTYPE Direct3DVolume8::GetDevice(Direct3DDevice8 **ppDevice)
HRESULT STDMETHODCALLTYPE Direct3DVolume8::GetDevice(IDirect3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
return D3DERR_INVALIDCALL;
Expand Down
30 changes: 15 additions & 15 deletions source/interface_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ void GenericQueryInterface(REFIID riid, LPVOID *ppvObj, Direct3DDevice8 *pDevice
if (ppvObj == nullptr || *ppvObj == nullptr || pDevice == nullptr)
return;

if (riid == __uuidof(Direct3D8))
if (riid == __uuidof(IDirect3D8))
{
Direct3D8 *pD3D8 = nullptr;
IDirect3D8 *pD3D8 = nullptr;
if (SUCCEEDED(pDevice->GetDirect3D(&pD3D8)) && pD3D8)
{
*ppvObj = pD3D8;
Expand All @@ -29,14 +29,14 @@ void GenericQueryInterface(REFIID riid, LPVOID *ppvObj, Direct3DDevice8 *pDevice
}
}

if (riid == __uuidof(Direct3DDevice8))
if (riid == __uuidof(IDirect3DDevice8))
{
*ppvObj = pDevice;
*ppvObj = static_cast<IDirect3DDevice8 *>(pDevice);
return;
}

#define QUERY_INTERFACE(x) \
if (riid == __uuidof(x)) \
if (riid == __uuidof(I ## x)) \
{ \
*ppvObj = pDevice->ProxyAddressLookupTable->FindAddress<x>(*ppvObj); \
return; \
Expand All @@ -54,25 +54,25 @@ void GenericQueryInterface(REFIID riid, LPVOID *ppvObj, Direct3DDevice8 *pDevice

REFIID ConvertREFIID(REFIID riid)
{
if (riid == __uuidof(Direct3D8))
if (riid == __uuidof(IDirect3D8))
return IID_IDirect3D9;
if (riid == __uuidof(Direct3DDevice8))
if (riid == __uuidof(IDirect3DDevice8))
return IID_IDirect3DDevice9;
if (riid == __uuidof(Direct3DTexture8))
if (riid == __uuidof(IDirect3DTexture8))
return IID_IDirect3DTexture9;
if (riid == __uuidof(Direct3DCubeTexture8))
if (riid == __uuidof(IDirect3DCubeTexture8))
return IID_IDirect3DCubeTexture9;
if (riid == __uuidof(Direct3DVolumeTexture8))
if (riid == __uuidof(IDirect3DVolumeTexture8))
return IID_IDirect3DVolumeTexture9;
if (riid == __uuidof(Direct3DVertexBuffer8))
if (riid == __uuidof(IDirect3DVertexBuffer8))
return IID_IDirect3DVertexBuffer9;
if (riid == __uuidof(Direct3DIndexBuffer8))
if (riid == __uuidof(IDirect3DIndexBuffer8))
return IID_IDirect3DIndexBuffer9;
if (riid == __uuidof(Direct3DSurface8))
if (riid == __uuidof(IDirect3DSurface8))
return IID_IDirect3DSurface9;
if (riid == __uuidof(Direct3DVolume8))
if (riid == __uuidof(IDirect3DVolume8))
return IID_IDirect3DVolume9;
if (riid == __uuidof(Direct3DSwapChain8))
if (riid == __uuidof(IDirect3DSwapChain8))
return IID_IDirect3DSwapChain9;
return riid;
}
11 changes: 11 additions & 0 deletions source/interface_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
#include <algorithm>
#include <unordered_map>

class Direct3D8;
class Direct3DDevice8;
class Direct3DSwapChain8;
class Direct3DTexture8;
class Direct3DCubeTexture8;
class Direct3DVolumeTexture8;
class Direct3DSurface8;
class Direct3DVolume8;
class Direct3DVertexBuffer8;
class Direct3DIndexBuffer8;

class AddressLookupTable
{
template <typename T>
Expand Down

0 comments on commit 94bdd33

Please sign in to comment.