mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Moved Direct3D parts to Direct3d namespace and subdirectory
This commit is contained in:
parent
55f840cb50
commit
1a9b4ce860
@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <guiddef.h>
|
||||
|
||||
#include "CompatPtr.h"
|
||||
|
||||
namespace CompatDepthBuffer
|
||||
{
|
||||
template <typename TDirect3d, typename TD3dDeviceDesc>
|
||||
void fixSupportedZBufferBitDepths(CompatPtr<TDirect3d> d3d, TD3dDeviceDesc& desc);
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "CompatVtable.h"
|
||||
#include "Direct3dVtblVisitor.h"
|
||||
|
||||
template <typename TDirect3d>
|
||||
class CompatDirect3d : public CompatVtable<CompatDirect3d<TDirect3d>, TDirect3d>
|
||||
{
|
||||
public:
|
||||
static void setCompatVtable(Vtable<TDirect3d>& vtable);
|
||||
};
|
@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "CompatVtable.h"
|
||||
#include "Direct3dDeviceVtblVisitor.h"
|
||||
|
||||
template <typename TDirect3dDevice>
|
||||
class CompatDirect3dDevice : public CompatVtable<CompatDirect3dDevice<TDirect3dDevice>, TDirect3dDevice>
|
||||
{
|
||||
public:
|
||||
static void setCompatVtable(Vtable<TDirect3dDevice>& vtable);
|
||||
};
|
@ -2,8 +2,6 @@
|
||||
|
||||
#include <d3d.h>
|
||||
|
||||
#include "CompatDirect3d.h"
|
||||
#include "CompatDirect3dDevice.h"
|
||||
#include "CompatPtr.h"
|
||||
#include "CompatRef.h"
|
||||
#include "DDraw/ActivateAppHandler.h"
|
||||
@ -14,108 +12,12 @@
|
||||
#include "DDraw/RealPrimarySurface.h"
|
||||
#include "DDraw/Repository.h"
|
||||
#include "DDrawLog.h"
|
||||
#include "DDrawProcs.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
void hookDirect3dDevice(CompatRef<IDirect3D3> d3d, CompatRef<IDirectDrawSurface4> renderTarget);
|
||||
void hookDirect3dDevice7(CompatRef<IDirect3D7> d3d, CompatRef<IDirectDrawSurface7> renderTarget);
|
||||
|
||||
template <typename CompatInterface>
|
||||
void hookVtable(const CompatPtr<typename CompatInterface::Interface>& intf);
|
||||
|
||||
template <typename TDirect3d, typename TDirectDraw>
|
||||
CompatPtr<TDirect3d> createDirect3d(CompatRef<TDirectDraw> dd)
|
||||
{
|
||||
CompatPtr<TDirect3d> d3d;
|
||||
HRESULT result = dd->QueryInterface(&dd, Compat::getIntfId<TDirect3d>(),
|
||||
reinterpret_cast<void**>(&d3d.getRef()));
|
||||
if (FAILED(result))
|
||||
{
|
||||
Compat::Log() << "Failed to create a Direct3D object for hooking: " << result;
|
||||
}
|
||||
return d3d;
|
||||
}
|
||||
|
||||
template <typename TDirect3dDevice, typename TDirect3d, typename TDirectDrawSurface,
|
||||
typename... Params>
|
||||
CompatPtr<TDirect3dDevice> createDirect3dDevice(
|
||||
CompatRef<TDirect3d> d3d, CompatRef<TDirectDrawSurface> renderTarget, Params... params)
|
||||
{
|
||||
CompatPtr<TDirect3dDevice> d3dDevice;
|
||||
HRESULT result = d3d->CreateDevice(
|
||||
&d3d, IID_IDirect3DRGBDevice, &renderTarget, &d3dDevice.getRef(), params...);
|
||||
if (FAILED(result))
|
||||
{
|
||||
Compat::Log() << "Failed to create a Direct3D device for hooking: " << result;
|
||||
}
|
||||
return d3dDevice;
|
||||
}
|
||||
|
||||
CompatPtr<IDirectDrawSurface7> createRenderTarget(CompatRef<IDirectDraw7> dd)
|
||||
{
|
||||
DDSURFACEDESC2 desc = {};
|
||||
desc.dwSize = sizeof(desc);
|
||||
desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
|
||||
desc.dwWidth = 1;
|
||||
desc.dwHeight = 1;
|
||||
desc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat);
|
||||
desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
||||
desc.ddpfPixelFormat.dwRGBBitCount = 32;
|
||||
desc.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
|
||||
desc.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
|
||||
desc.ddpfPixelFormat.dwBBitMask = 0x000000FF;
|
||||
desc.ddsCaps.dwCaps = DDSCAPS_3DDEVICE;
|
||||
|
||||
CompatPtr<IDirectDrawSurface7> renderTarget;
|
||||
HRESULT result = dd->CreateSurface(&dd, &desc, &renderTarget.getRef(), nullptr);
|
||||
if (FAILED(result))
|
||||
{
|
||||
Compat::Log() << "Failed to create a render target for hooking: " << result;
|
||||
}
|
||||
return renderTarget;
|
||||
}
|
||||
|
||||
void hookDirect3d(CompatRef<IDirectDraw> dd, CompatRef<IDirectDrawSurface4> renderTarget)
|
||||
{
|
||||
CompatPtr<IDirect3D3> d3d(createDirect3d<IDirect3D3>(dd));
|
||||
if (d3d)
|
||||
{
|
||||
hookVtable<CompatDirect3d<IDirect3D>>(d3d);
|
||||
hookVtable<CompatDirect3d<IDirect3D2>>(d3d);
|
||||
hookVtable<CompatDirect3d<IDirect3D3>>(d3d);
|
||||
hookDirect3dDevice(*d3d, renderTarget);
|
||||
}
|
||||
}
|
||||
|
||||
void hookDirect3d7(CompatRef<IDirectDraw7> dd, CompatRef<IDirectDrawSurface7> renderTarget)
|
||||
{
|
||||
CompatPtr<IDirect3D7> d3d(createDirect3d<IDirect3D7>(dd));
|
||||
if (d3d)
|
||||
{
|
||||
hookVtable<CompatDirect3d<IDirect3D7>>(d3d);
|
||||
hookDirect3dDevice7(*d3d, renderTarget);
|
||||
}
|
||||
}
|
||||
|
||||
void hookDirect3dDevice(CompatRef<IDirect3D3> d3d, CompatRef<IDirectDrawSurface4> renderTarget)
|
||||
{
|
||||
CompatPtr<IDirect3DDevice3> d3dDevice(
|
||||
createDirect3dDevice<IDirect3DDevice3>(d3d, renderTarget, nullptr));
|
||||
|
||||
hookVtable<CompatDirect3dDevice<IDirect3DDevice>>(d3dDevice);
|
||||
hookVtable<CompatDirect3dDevice<IDirect3DDevice2>>(d3dDevice);
|
||||
hookVtable<CompatDirect3dDevice<IDirect3DDevice3>>(d3dDevice);
|
||||
}
|
||||
|
||||
void hookDirect3dDevice7(CompatRef<IDirect3D7> d3d, CompatRef<IDirectDrawSurface7> renderTarget)
|
||||
{
|
||||
CompatPtr<IDirect3DDevice7> d3dDevice(
|
||||
createDirect3dDevice<IDirect3DDevice7>(d3d, renderTarget));
|
||||
|
||||
hookVtable<CompatDirect3dDevice<IDirect3DDevice7>>(d3dDevice);
|
||||
}
|
||||
|
||||
void hookDirectDraw(CompatRef<IDirectDraw7> dd)
|
||||
{
|
||||
DDraw::DirectDraw<IDirectDraw7>::s_origVtable = *(&dd)->lpVtbl;
|
||||
@ -206,14 +108,6 @@ namespace DDraw
|
||||
hookDirectDrawSurface(*dd7);
|
||||
hookDirectDrawPalette(*dd7);
|
||||
|
||||
CompatPtr<IDirectDrawSurface7> renderTarget7(createRenderTarget(*dd7));
|
||||
if (renderTarget7)
|
||||
{
|
||||
CompatPtr<IDirectDrawSurface4> renderTarget4(renderTarget7);
|
||||
hookDirect3d(*dd, *renderTarget4);
|
||||
hookDirect3d7(*dd7, *renderTarget7);
|
||||
}
|
||||
|
||||
ActivateAppHandler::installHooks();
|
||||
}
|
||||
|
||||
|
@ -93,6 +93,7 @@
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<ObjectFileName>$(IntDir)%(RelativeDir)</ObjectFileName>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<ModuleDefinitionFile>DDrawCompat.def</ModuleDefinitionFile>
|
||||
@ -121,6 +122,7 @@
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;DDRAWCOMPAT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<ObjectFileName>$(IntDir)%(RelativeDir)</ObjectFileName>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<ModuleDefinitionFile>DDrawCompat.def</ModuleDefinitionFile>
|
||||
@ -151,9 +153,6 @@
|
||||
<ClInclude Include="CompatD3dDdiAdapterFuncs.h" />
|
||||
<ClInclude Include="CompatD3dDdiDeviceCallbacks.h" />
|
||||
<ClInclude Include="CompatD3dDdiDeviceFuncs.h" />
|
||||
<ClInclude Include="CompatDepthBuffer.h" />
|
||||
<ClInclude Include="CompatDirect3d.h" />
|
||||
<ClInclude Include="CompatDirect3dDevice.h" />
|
||||
<ClInclude Include="CompatFontSmoothing.h" />
|
||||
<ClInclude Include="CompatHooks.h" />
|
||||
<ClInclude Include="CompatPtr.h" />
|
||||
@ -184,8 +183,12 @@
|
||||
<ClInclude Include="DDraw\IReleaseNotifier.h" />
|
||||
<ClInclude Include="DDraw\RealPrimarySurface.h" />
|
||||
<ClInclude Include="Direct3dDeviceVtblVisitor.h" />
|
||||
<ClInclude Include="Direct3dTypes.h" />
|
||||
<ClInclude Include="Direct3dVtblVisitor.h" />
|
||||
<ClInclude Include="Direct3d\DepthBuffer.h" />
|
||||
<ClInclude Include="Direct3d\Direct3d.h" />
|
||||
<ClInclude Include="Direct3d\Direct3dDevice.h" />
|
||||
<ClInclude Include="Direct3d\Hooks.h" />
|
||||
<ClInclude Include="Direct3d\Types.h" />
|
||||
<ClInclude Include="DirectDrawPaletteVtblVisitor.h" />
|
||||
<ClInclude Include="DirectDrawSurfaceVtblVisitor.h" />
|
||||
<ClInclude Include="DirectDrawVtblVisitor.h" />
|
||||
@ -209,9 +212,6 @@
|
||||
<ClCompile Include="CompatD3dDdiAdapterFuncs.cpp" />
|
||||
<ClCompile Include="CompatD3dDdiDeviceCallbacks.cpp" />
|
||||
<ClCompile Include="CompatD3dDdiDeviceFuncs.cpp" />
|
||||
<ClCompile Include="CompatDepthBuffer.cpp" />
|
||||
<ClCompile Include="CompatDirect3d.cpp" />
|
||||
<ClCompile Include="CompatDirect3dDevice.cpp" />
|
||||
<ClCompile Include="CompatFontSmoothing.cpp" />
|
||||
<ClCompile Include="CompatHooks.cpp" />
|
||||
<ClCompile Include="CompatRegistry.cpp" />
|
||||
@ -228,6 +228,10 @@
|
||||
<ClCompile Include="DDraw\Repository.cpp" />
|
||||
<ClCompile Include="DDraw\IReleaseNotifier.cpp" />
|
||||
<ClCompile Include="DDraw\RealPrimarySurface.cpp" />
|
||||
<ClCompile Include="Direct3d\DepthBuffer.cpp" />
|
||||
<ClCompile Include="Direct3d\Direct3d.cpp" />
|
||||
<ClCompile Include="Direct3d\Direct3dDevice.cpp" />
|
||||
<ClCompile Include="Direct3d\Hooks.cpp" />
|
||||
<ClCompile Include="DllMain.cpp" />
|
||||
<ClCompile Include="DDrawProcs.cpp" />
|
||||
<ClCompile Include="Gdi\Gdi.cpp" />
|
||||
|
@ -25,6 +25,12 @@
|
||||
<Filter Include="Source Files\DDraw">
|
||||
<UniqueIdentifier>{bcc85014-8548-43ff-902f-16bcb6a0e96b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Direct3d">
|
||||
<UniqueIdentifier>{1e5628f5-39bf-4080-ae94-938081671cf8}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Direct3d">
|
||||
<UniqueIdentifier>{08a23b36-cd96-4214-985b-0473ecf6ecab}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="DDrawProcs.h">
|
||||
@ -81,21 +87,9 @@
|
||||
<ClInclude Include="Direct3dVtblVisitor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CompatDirect3d.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Direct3dDeviceVtblVisitor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CompatDirect3dDevice.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Direct3dTypes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CompatDepthBuffer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="D3dDdiAdapterCallbacksVisitor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -195,6 +189,21 @@
|
||||
<ClInclude Include="DDraw\DirectDrawSurface.h">
|
||||
<Filter>Header Files\DDraw</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Direct3d\Direct3d.h">
|
||||
<Filter>Header Files\Direct3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Direct3d\Direct3dDevice.h">
|
||||
<Filter>Header Files\Direct3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Direct3d\DepthBuffer.h">
|
||||
<Filter>Header Files\Direct3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Direct3d\Types.h">
|
||||
<Filter>Header Files\Direct3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Direct3d\Hooks.h">
|
||||
<Filter>Header Files\Direct3d</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="DllMain.cpp">
|
||||
@ -224,15 +233,6 @@
|
||||
<ClCompile Include="CompatHooks.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CompatDirect3d.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CompatDirect3dDevice.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CompatDepthBuffer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CompatD3dDdiDeviceFuncs.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -311,6 +311,18 @@
|
||||
<ClCompile Include="DDraw\DirectDrawSurface.cpp">
|
||||
<Filter>Source Files\DDraw</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Direct3d\Direct3d.cpp">
|
||||
<Filter>Source Files\Direct3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Direct3d\Direct3dDevice.cpp">
|
||||
<Filter>Source Files\Direct3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Direct3d\DepthBuffer.cpp">
|
||||
<Filter>Source Files\Direct3d</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Direct3d\Hooks.cpp">
|
||||
<Filter>Source Files\Direct3d</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="DDrawCompat.def">
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include "CompatDepthBuffer.h"
|
||||
#include "Direct3d/DepthBuffer.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -101,24 +101,27 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
namespace CompatDepthBuffer
|
||||
namespace Direct3d
|
||||
{
|
||||
template <typename TDirect3d, typename TD3dDeviceDesc>
|
||||
void fixSupportedZBufferBitDepths(
|
||||
CompatPtr<TDirect3d> d3d, TD3dDeviceDesc& desc)
|
||||
namespace DepthBuffer
|
||||
{
|
||||
if (isHardwareZBufferSupported(desc))
|
||||
template <typename TDirect3d, typename TD3dDeviceDesc>
|
||||
void fixSupportedZBufferBitDepths(
|
||||
CompatPtr<TDirect3d> d3d, TD3dDeviceDesc& desc)
|
||||
{
|
||||
const DWORD supportedBitDepths = getSupportedZBufferBitDepths(d3d, getDeviceGuid(desc));
|
||||
if (0 != supportedBitDepths && supportedBitDepths != desc.dwDeviceZBufferBitDepth)
|
||||
if (isHardwareZBufferSupported(desc))
|
||||
{
|
||||
logSupportedZBufferBitDepthsChanged(
|
||||
d3d, getDeviceGuid(desc), desc.dwDeviceZBufferBitDepth, supportedBitDepths);
|
||||
desc.dwDeviceZBufferBitDepth = supportedBitDepths;
|
||||
const DWORD supportedBitDepths = getSupportedZBufferBitDepths(d3d, getDeviceGuid(desc));
|
||||
if (0 != supportedBitDepths && supportedBitDepths != desc.dwDeviceZBufferBitDepth)
|
||||
{
|
||||
logSupportedZBufferBitDepthsChanged(
|
||||
d3d, getDeviceGuid(desc), desc.dwDeviceZBufferBitDepth, supportedBitDepths);
|
||||
desc.dwDeviceZBufferBitDepth = supportedBitDepths;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template void fixSupportedZBufferBitDepths(CompatPtr<IDirect3D3>, D3DDEVICEDESC&);
|
||||
template void fixSupportedZBufferBitDepths(CompatPtr<IDirect3D7>, D3DDEVICEDESC7&);
|
||||
template void fixSupportedZBufferBitDepths(CompatPtr<IDirect3D3>, D3DDEVICEDESC&);
|
||||
template void fixSupportedZBufferBitDepths(CompatPtr<IDirect3D7>, D3DDEVICEDESC7&);
|
||||
}
|
||||
}
|
14
DDrawCompat/Direct3d/DepthBuffer.h
Normal file
14
DDrawCompat/Direct3d/DepthBuffer.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <guiddef.h>
|
||||
|
||||
#include "CompatPtr.h"
|
||||
|
||||
namespace Direct3d
|
||||
{
|
||||
namespace DepthBuffer
|
||||
{
|
||||
template <typename TDirect3d, typename TD3dDeviceDesc>
|
||||
void fixSupportedZBufferBitDepths(CompatPtr<TDirect3d> d3d, TD3dDeviceDesc& desc);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#include "CompatDepthBuffer.h"
|
||||
#include "CompatDirect3d.h"
|
||||
#include "CompatPtr.h"
|
||||
#include "Direct3dTypes.h"
|
||||
#include "Direct3d/DepthBuffer.h"
|
||||
#include "Direct3d/Direct3d.h"
|
||||
#include "Direct3d/Types.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -9,7 +9,7 @@ namespace
|
||||
struct EnumDevicesParams
|
||||
{
|
||||
CompatPtr<TDirect3d> d3d;
|
||||
typename Types<TDirect3d>::TD3dEnumDevicesCallback enumDevicesCallback;
|
||||
typename Direct3d::Types<TDirect3d>::TD3dEnumDevicesCallback enumDevicesCallback;
|
||||
void* userArg;
|
||||
};
|
||||
|
||||
@ -22,7 +22,7 @@ namespace
|
||||
LPVOID lpContext)
|
||||
{
|
||||
auto& params = *reinterpret_cast<EnumDevicesParams<IDirect3D3>*>(lpContext);
|
||||
CompatDepthBuffer::fixSupportedZBufferBitDepths<IDirect3D3>(params.d3d, *lpD3DHWDeviceDesc);
|
||||
Direct3d::DepthBuffer::fixSupportedZBufferBitDepths<IDirect3D3>(params.d3d, *lpD3DHWDeviceDesc);
|
||||
return params.enumDevicesCallback(lpGuid, lpDeviceDescription, lpDeviceName,
|
||||
lpD3DHWDeviceDesc, lpD3DHELDeviceDesc, params.userArg);
|
||||
}
|
||||
@ -34,7 +34,7 @@ namespace
|
||||
LPVOID lpContext)
|
||||
{
|
||||
auto& params = *reinterpret_cast<EnumDevicesParams<IDirect3D7>*>(lpContext);
|
||||
CompatDepthBuffer::fixSupportedZBufferBitDepths<IDirect3D7>(params.d3d, *lpD3DDeviceDesc);
|
||||
Direct3d::DepthBuffer::fixSupportedZBufferBitDepths<IDirect3D7>(params.d3d, *lpD3DDeviceDesc);
|
||||
return params.enumDevicesCallback(lpDeviceDescription, lpDeviceName,
|
||||
lpD3DDeviceDesc, params.userArg);
|
||||
}
|
||||
@ -49,7 +49,7 @@ namespace
|
||||
This, lpEnumDevicesCallback, lpUserArg);
|
||||
}
|
||||
|
||||
typedef typename Types<TDirect3d>::TDirect3dHighest TDirect3dHighest;
|
||||
typedef typename Direct3d::Types<TDirect3d>::TDirect3dHighest TDirect3dHighest;
|
||||
CompatPtr<TDirect3dHighest> d3d(Compat::queryInterface<TDirect3dHighest>(This));
|
||||
|
||||
EnumDevicesParams<TDirect3dHighest> params = { d3d, lpEnumDevicesCallback, lpUserArg };
|
||||
@ -58,14 +58,17 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TDirect3d>
|
||||
void CompatDirect3d<TDirect3d>::setCompatVtable(Vtable<TDirect3d>& vtable)
|
||||
namespace Direct3d
|
||||
{
|
||||
vtable.EnumDevices = &enumDevices;
|
||||
// No need to fix FindDevice since it uses EnumDevices
|
||||
}
|
||||
template <typename TDirect3d>
|
||||
void Direct3d<TDirect3d>::setCompatVtable(Vtable<TDirect3d>& vtable)
|
||||
{
|
||||
vtable.EnumDevices = &enumDevices;
|
||||
// No need to fix FindDevice since it uses EnumDevices
|
||||
}
|
||||
|
||||
template CompatDirect3d<IDirect3D>;
|
||||
template CompatDirect3d<IDirect3D2>;
|
||||
template CompatDirect3d<IDirect3D3>;
|
||||
template CompatDirect3d<IDirect3D7>;
|
||||
template Direct3d<IDirect3D>;
|
||||
template Direct3d<IDirect3D2>;
|
||||
template Direct3d<IDirect3D3>;
|
||||
template Direct3d<IDirect3D7>;
|
||||
}
|
14
DDrawCompat/Direct3d/Direct3d.h
Normal file
14
DDrawCompat/Direct3d/Direct3d.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "CompatVtable.h"
|
||||
#include "Direct3dVtblVisitor.h"
|
||||
|
||||
namespace Direct3d
|
||||
{
|
||||
template <typename TDirect3d>
|
||||
class Direct3d : public CompatVtable<Direct3d<TDirect3d>, TDirect3d>
|
||||
{
|
||||
public:
|
||||
static void setCompatVtable(Vtable<TDirect3d>& vtable);
|
||||
};
|
||||
}
|
@ -1,21 +1,21 @@
|
||||
#include "CompatDepthBuffer.h"
|
||||
#include "CompatDirect3dDevice.h"
|
||||
#include "CompatPtr.h"
|
||||
#include "CompatRef.h"
|
||||
#include "Direct3dTypes.h"
|
||||
#include "Direct3d/DepthBuffer.h"
|
||||
#include "Direct3d/Direct3dDevice.h"
|
||||
#include "Direct3d/Types.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename TDirect3dDevice, typename TD3dDeviceDesc>
|
||||
void fixSupportedZBufferBitDepths(CompatRef<TDirect3dDevice> d3dDevice, TD3dDeviceDesc& desc)
|
||||
{
|
||||
typedef typename Types<TDirect3dDevice>::TDirect3d TDirect3d;
|
||||
typedef typename Direct3d::Types<TDirect3dDevice>::TDirect3d TDirect3d;
|
||||
CompatPtr<TDirect3d> d3d;
|
||||
if (SUCCEEDED(CompatVtableBase<TDirect3dDevice>::s_origVtable.GetDirect3D(
|
||||
&d3dDevice, &d3d.getRef())))
|
||||
{
|
||||
typedef typename Types<TDirect3dDevice>::TDirect3dHighest TDirect3dHighest;
|
||||
CompatDepthBuffer::fixSupportedZBufferBitDepths<TDirect3dHighest>(d3d, desc);
|
||||
typedef typename Direct3d::Types<TDirect3dDevice>::TDirect3dHighest TDirect3dHighest;
|
||||
Direct3d::DepthBuffer::fixSupportedZBufferBitDepths<TDirect3dHighest>(d3d, desc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,13 +35,16 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TDirect3dDevice>
|
||||
void CompatDirect3dDevice<TDirect3dDevice>::setCompatVtable(Vtable<TDirect3dDevice>& vtable)
|
||||
namespace Direct3d
|
||||
{
|
||||
vtable.GetCaps = &getCaps;
|
||||
}
|
||||
template <typename TDirect3dDevice>
|
||||
void Direct3dDevice<TDirect3dDevice>::setCompatVtable(Vtable<TDirect3dDevice>& vtable)
|
||||
{
|
||||
vtable.GetCaps = &getCaps;
|
||||
}
|
||||
|
||||
template CompatDirect3dDevice<IDirect3DDevice>;
|
||||
template CompatDirect3dDevice<IDirect3DDevice2>;
|
||||
template CompatDirect3dDevice<IDirect3DDevice3>;
|
||||
template CompatDirect3dDevice<IDirect3DDevice7>;
|
||||
template Direct3dDevice<IDirect3DDevice>;
|
||||
template Direct3dDevice<IDirect3DDevice2>;
|
||||
template Direct3dDevice<IDirect3DDevice3>;
|
||||
template Direct3dDevice<IDirect3DDevice7>;
|
||||
}
|
14
DDrawCompat/Direct3d/Direct3dDevice.h
Normal file
14
DDrawCompat/Direct3d/Direct3dDevice.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "CompatVtable.h"
|
||||
#include "Direct3dDeviceVtblVisitor.h"
|
||||
|
||||
namespace Direct3d
|
||||
{
|
||||
template <typename TDirect3dDevice>
|
||||
class Direct3dDevice : public CompatVtable<Direct3dDevice<TDirect3dDevice>, TDirect3dDevice>
|
||||
{
|
||||
public:
|
||||
static void setCompatVtable(Vtable<TDirect3dDevice>& vtable);
|
||||
};
|
||||
}
|
141
DDrawCompat/Direct3d/Hooks.cpp
Normal file
141
DDrawCompat/Direct3d/Hooks.cpp
Normal file
@ -0,0 +1,141 @@
|
||||
#define CINTERFACE
|
||||
|
||||
#include <d3d.h>
|
||||
|
||||
#include "CompatPtr.h"
|
||||
#include "CompatRef.h"
|
||||
#include "DDraw/Repository.h"
|
||||
#include "DDrawLog.h"
|
||||
#include "Direct3d/Direct3d.h"
|
||||
#include "Direct3d/Direct3dDevice.h"
|
||||
#include "Direct3d/Hooks.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
void hookDirect3dDevice(CompatRef<IDirect3D3> d3d, CompatRef<IDirectDrawSurface4> renderTarget);
|
||||
void hookDirect3dDevice7(CompatRef<IDirect3D7> d3d, CompatRef<IDirectDrawSurface7> renderTarget);
|
||||
|
||||
template <typename CompatInterface>
|
||||
void hookVtable(const CompatPtr<typename CompatInterface::Interface>& intf);
|
||||
|
||||
template <typename TDirect3d, typename TDirectDraw>
|
||||
CompatPtr<TDirect3d> createDirect3d(CompatRef<TDirectDraw> dd)
|
||||
{
|
||||
CompatPtr<TDirect3d> d3d;
|
||||
HRESULT result = dd->QueryInterface(&dd, Compat::getIntfId<TDirect3d>(),
|
||||
reinterpret_cast<void**>(&d3d.getRef()));
|
||||
if (FAILED(result))
|
||||
{
|
||||
Compat::Log() << "Failed to create a Direct3D object for hooking: " << result;
|
||||
}
|
||||
return d3d;
|
||||
}
|
||||
|
||||
template <typename TDirect3dDevice, typename TDirect3d, typename TDirectDrawSurface,
|
||||
typename... Params>
|
||||
CompatPtr<TDirect3dDevice> createDirect3dDevice(
|
||||
CompatRef<TDirect3d> d3d, CompatRef<TDirectDrawSurface> renderTarget, Params... params)
|
||||
{
|
||||
CompatPtr<TDirect3dDevice> d3dDevice;
|
||||
HRESULT result = d3d->CreateDevice(
|
||||
&d3d, IID_IDirect3DRGBDevice, &renderTarget, &d3dDevice.getRef(), params...);
|
||||
if (FAILED(result))
|
||||
{
|
||||
Compat::Log() << "Failed to create a Direct3D device for hooking: " << result;
|
||||
}
|
||||
return d3dDevice;
|
||||
}
|
||||
|
||||
CompatPtr<IDirectDrawSurface7> createRenderTarget(CompatRef<IDirectDraw7> dd)
|
||||
{
|
||||
DDSURFACEDESC2 desc = {};
|
||||
desc.dwSize = sizeof(desc);
|
||||
desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
|
||||
desc.dwWidth = 1;
|
||||
desc.dwHeight = 1;
|
||||
desc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat);
|
||||
desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
||||
desc.ddpfPixelFormat.dwRGBBitCount = 32;
|
||||
desc.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
|
||||
desc.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
|
||||
desc.ddpfPixelFormat.dwBBitMask = 0x000000FF;
|
||||
desc.ddsCaps.dwCaps = DDSCAPS_3DDEVICE;
|
||||
|
||||
CompatPtr<IDirectDrawSurface7> renderTarget;
|
||||
HRESULT result = dd->CreateSurface(&dd, &desc, &renderTarget.getRef(), nullptr);
|
||||
if (FAILED(result))
|
||||
{
|
||||
Compat::Log() << "Failed to create a render target for hooking: " << result;
|
||||
}
|
||||
return renderTarget;
|
||||
}
|
||||
|
||||
void hookDirect3d(CompatRef<IDirectDraw> dd, CompatRef<IDirectDrawSurface4> renderTarget)
|
||||
{
|
||||
CompatPtr<IDirect3D3> d3d(createDirect3d<IDirect3D3>(dd));
|
||||
if (d3d)
|
||||
{
|
||||
hookVtable<Direct3d::Direct3d<IDirect3D>>(d3d);
|
||||
hookVtable<Direct3d::Direct3d<IDirect3D2>>(d3d);
|
||||
hookVtable<Direct3d::Direct3d<IDirect3D3>>(d3d);
|
||||
hookDirect3dDevice(*d3d, renderTarget);
|
||||
}
|
||||
}
|
||||
|
||||
void hookDirect3d7(CompatRef<IDirectDraw7> dd, CompatRef<IDirectDrawSurface7> renderTarget)
|
||||
{
|
||||
CompatPtr<IDirect3D7> d3d(createDirect3d<IDirect3D7>(dd));
|
||||
if (d3d)
|
||||
{
|
||||
hookVtable<Direct3d::Direct3d<IDirect3D7>>(d3d);
|
||||
hookDirect3dDevice7(*d3d, renderTarget);
|
||||
}
|
||||
}
|
||||
|
||||
void hookDirect3dDevice(CompatRef<IDirect3D3> d3d, CompatRef<IDirectDrawSurface4> renderTarget)
|
||||
{
|
||||
CompatPtr<IDirect3DDevice3> d3dDevice(
|
||||
createDirect3dDevice<IDirect3DDevice3>(d3d, renderTarget, nullptr));
|
||||
|
||||
hookVtable<Direct3d::Direct3dDevice<IDirect3DDevice>>(d3dDevice);
|
||||
hookVtable<Direct3d::Direct3dDevice<IDirect3DDevice2>>(d3dDevice);
|
||||
hookVtable<Direct3d::Direct3dDevice<IDirect3DDevice3>>(d3dDevice);
|
||||
}
|
||||
|
||||
void hookDirect3dDevice7(CompatRef<IDirect3D7> d3d, CompatRef<IDirectDrawSurface7> renderTarget)
|
||||
{
|
||||
CompatPtr<IDirect3DDevice7> d3dDevice(
|
||||
createDirect3dDevice<IDirect3DDevice7>(d3d, renderTarget));
|
||||
|
||||
hookVtable<Direct3d::Direct3dDevice<IDirect3DDevice7>>(d3dDevice);
|
||||
}
|
||||
|
||||
template <typename CompatInterface>
|
||||
void hookVtable(const CompatPtr<typename CompatInterface::Interface>& intf)
|
||||
{
|
||||
CompatInterface::hookVtable(intf.get()->lpVtbl);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Direct3d
|
||||
{
|
||||
void installHooks()
|
||||
{
|
||||
auto dd7(DDraw::Repository::getDirectDraw());
|
||||
CompatPtr<IDirectDraw> dd;
|
||||
CALL_ORIG_DDRAW(DirectDrawCreate, nullptr, &dd.getRef(), nullptr);
|
||||
if (!dd || !dd7 || FAILED(dd->SetCooperativeLevel(dd, nullptr, DDSCL_NORMAL)))
|
||||
{
|
||||
Compat::Log() << "Failed to hook Direct3d interfaces";
|
||||
return;
|
||||
}
|
||||
|
||||
CompatPtr<IDirectDrawSurface7> renderTarget7(createRenderTarget(*dd7));
|
||||
if (renderTarget7)
|
||||
{
|
||||
CompatPtr<IDirectDrawSurface4> renderTarget4(renderTarget7);
|
||||
hookDirect3d(*dd, *renderTarget4);
|
||||
hookDirect3d7(*dd7, *renderTarget7);
|
||||
}
|
||||
}
|
||||
}
|
6
DDrawCompat/Direct3d/Hooks.h
Normal file
6
DDrawCompat/Direct3d/Hooks.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace Direct3d
|
||||
{
|
||||
void installHooks();
|
||||
}
|
57
DDrawCompat/Direct3d/Types.h
Normal file
57
DDrawCompat/Direct3d/Types.h
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#define CINTERFACE
|
||||
|
||||
#include <d3d.h>
|
||||
|
||||
namespace Direct3d
|
||||
{
|
||||
struct Types1
|
||||
{
|
||||
typedef IDirect3D TDirect3d;
|
||||
typedef IDirect3D3 TDirect3dHighest;
|
||||
typedef IDirect3DDevice TDirect3dDevice;
|
||||
typedef D3DDEVICEDESC TD3dDeviceDesc;
|
||||
typedef LPD3DENUMDEVICESCALLBACK TD3dEnumDevicesCallback;
|
||||
};
|
||||
|
||||
struct Types2
|
||||
{
|
||||
typedef IDirect3D2 TDirect3d;
|
||||
typedef IDirect3D3 TDirect3dHighest;
|
||||
typedef IDirect3DDevice2 TDirect3dDevice;
|
||||
typedef D3DDEVICEDESC TD3dDeviceDesc;
|
||||
typedef LPD3DENUMDEVICESCALLBACK TD3dEnumDevicesCallback;
|
||||
};
|
||||
|
||||
struct Types3
|
||||
{
|
||||
typedef IDirect3D3 TDirect3d;
|
||||
typedef IDirect3D3 TDirect3dHighest;
|
||||
typedef IDirect3DDevice3 TDirect3dDevice;
|
||||
typedef D3DDEVICEDESC TD3dDeviceDesc;
|
||||
typedef LPD3DENUMDEVICESCALLBACK TD3dEnumDevicesCallback;
|
||||
};
|
||||
|
||||
struct Types7
|
||||
{
|
||||
typedef IDirect3D7 TDirect3d;
|
||||
typedef IDirect3D7 TDirect3dHighest;
|
||||
typedef IDirect3DDevice7 TDirect3dDevice;
|
||||
typedef D3DDEVICEDESC7 TD3dDeviceDesc;
|
||||
typedef LPD3DENUMDEVICESCALLBACK7 TD3dEnumDevicesCallback;
|
||||
};
|
||||
|
||||
template <typename Interface>
|
||||
struct Types;
|
||||
|
||||
template <> struct Types<IDirect3D> : Types1 {};
|
||||
template <> struct Types<IDirect3D2> : Types2 {};
|
||||
template <> struct Types<IDirect3D3> : Types3 {};
|
||||
template <> struct Types<IDirect3D7> : Types7 {};
|
||||
|
||||
template <> struct Types<IDirect3DDevice> : Types1 {};
|
||||
template <> struct Types<IDirect3DDevice2> : Types2 {};
|
||||
template <> struct Types<IDirect3DDevice3> : Types3 {};
|
||||
template <> struct Types<IDirect3DDevice7> : Types7 {};
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define CINTERFACE
|
||||
|
||||
#include <d3d.h>
|
||||
|
||||
struct Direct3dTypes
|
||||
{
|
||||
typedef IDirect3D TDirect3d;
|
||||
typedef IDirect3D3 TDirect3dHighest;
|
||||
typedef IDirect3DDevice TDirect3dDevice;
|
||||
typedef D3DDEVICEDESC TD3dDeviceDesc;
|
||||
typedef LPD3DENUMDEVICESCALLBACK TD3dEnumDevicesCallback;
|
||||
};
|
||||
|
||||
struct Direct3dTypes2
|
||||
{
|
||||
typedef IDirect3D2 TDirect3d;
|
||||
typedef IDirect3D3 TDirect3dHighest;
|
||||
typedef IDirect3DDevice2 TDirect3dDevice;
|
||||
typedef D3DDEVICEDESC TD3dDeviceDesc;
|
||||
typedef LPD3DENUMDEVICESCALLBACK TD3dEnumDevicesCallback;
|
||||
};
|
||||
|
||||
struct Direct3dTypes3
|
||||
{
|
||||
typedef IDirect3D3 TDirect3d;
|
||||
typedef IDirect3D3 TDirect3dHighest;
|
||||
typedef IDirect3DDevice3 TDirect3dDevice;
|
||||
typedef D3DDEVICEDESC TD3dDeviceDesc;
|
||||
typedef LPD3DENUMDEVICESCALLBACK TD3dEnumDevicesCallback;
|
||||
};
|
||||
|
||||
struct Direct3dTypes7
|
||||
{
|
||||
typedef IDirect3D7 TDirect3d;
|
||||
typedef IDirect3D7 TDirect3dHighest;
|
||||
typedef IDirect3DDevice7 TDirect3dDevice;
|
||||
typedef D3DDEVICEDESC7 TD3dDeviceDesc;
|
||||
typedef LPD3DENUMDEVICESCALLBACK7 TD3dEnumDevicesCallback;
|
||||
};
|
||||
|
||||
template <typename Interface>
|
||||
struct Types;
|
||||
|
||||
#define D3D_CONCAT(x, y, ...) x##y
|
||||
|
||||
#define D3D_TYPES(Interface, ...) \
|
||||
template <> \
|
||||
struct Types<D3D_CONCAT(Interface, __VA_ARGS__)> : D3D_CONCAT(Direct3dTypes, __VA_ARGS__) \
|
||||
{}
|
||||
|
||||
D3D_TYPES(IDirect3D);
|
||||
D3D_TYPES(IDirect3D, 2);
|
||||
D3D_TYPES(IDirect3D, 3);
|
||||
D3D_TYPES(IDirect3D, 7);
|
||||
|
||||
D3D_TYPES(IDirect3DDevice);
|
||||
D3D_TYPES(IDirect3DDevice, 2);
|
||||
D3D_TYPES(IDirect3DDevice, 3);
|
||||
D3D_TYPES(IDirect3DDevice, 7);
|
||||
|
||||
#undef D3D_TYPES
|
||||
#undef D3D_CONCAT
|
@ -12,6 +12,7 @@
|
||||
#include "DDraw/DisplayMode.h"
|
||||
#include "DDraw/Hooks.h"
|
||||
#include "DDrawProcs.h"
|
||||
#include "Direct3d/Hooks.h"
|
||||
#include "Gdi/Gdi.h"
|
||||
#include "Time.h"
|
||||
|
||||
@ -31,6 +32,8 @@ namespace
|
||||
D3dDdiHooks::installHooks();
|
||||
Compat::Log() << "Installing DirectDraw hooks";
|
||||
DDraw::installHooks();
|
||||
Compat::Log() << "Installing Direct3D hooks";
|
||||
Direct3d::installHooks();
|
||||
Compat::Log() << "Installing GDI hooks";
|
||||
Gdi::installHooks();
|
||||
Compat::Log() << "Installing registry hooks";
|
||||
|
Loading…
x
Reference in New Issue
Block a user