diff --git a/README.md b/README.md
index c27bb8c..6b1ba64 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ A quick overview of what some of the source code files contain:
|[d3d8to9_base.cpp](source/d3d8to9_base.cpp) | Implementation of the `IDirect3D8` interface, including device creation |
|[d3d8to9_device.cpp](source/d3d8to9_device.cpp) | Implementation of the `IDirect3DDevice8` interface, including shader conversion |
|[d3d8types.hpp](source/d3d8types.hpp) | Declaration of all used D3D8 types one would otherwise find in d3d8.h |
-|[lookup_table.hpp](source/lookup_table.hpp) | Table to map D3D9 interface addresses to their matching D3D8 implementations |
+|[interface_query.hpp](source/interface_query.hpp) | Table to map D3D9 interface addresses to their matching D3D8 implementations |
## Contributing
diff --git a/d3d8to9.vcxproj b/d3d8to9.vcxproj
index e714bda..d7ad540 100644
--- a/d3d8to9.vcxproj
+++ b/d3d8to9.vcxproj
@@ -82,14 +82,13 @@
-
-
+
diff --git a/d3d8to9.vcxproj.filters b/d3d8to9.vcxproj.filters
index 0d1c099..5aa7930 100644
--- a/d3d8to9.vcxproj.filters
+++ b/d3d8to9.vcxproj.filters
@@ -9,9 +9,6 @@
-
- helpers
-
@@ -21,7 +18,7 @@
-
+
helpers
@@ -29,17 +26,17 @@
-
- helpers
+
+ resources
+
helpers
-
- resources
+
+ helpers
-
-
+
helpers
diff --git a/source/d3d8to9.hpp b/source/d3d8to9.hpp
index 8f25d55..10d36bf 100644
--- a/source/d3d8to9.hpp
+++ b/source/d3d8to9.hpp
@@ -5,8 +5,8 @@
#pragma once
-#include "d3d8types.hpp"
#include
+#include "d3d8types.hpp"
class __declspec(uuid("1DD9E8DA-1C77-4D40-B0CF-98FEFDFF9512")) Direct3D8;
class __declspec(uuid("7385E5DF-8FE8-41D5-86B6-D7B48547B6CF")) Direct3DDevice8;
@@ -21,7 +21,7 @@ class __declspec(uuid("BD7349F5-14F1-42E4-9C79-972380DB40C0")) Direct3DVolume8;
class __declspec(uuid("8AEEEAC7-05F9-44D4-B591-000B0DF1CB95")) Direct3DVertexBuffer8;
class __declspec(uuid("0E689C9A-053D-44A0-9D92-DB0E3D750F86")) Direct3DIndexBuffer8;
-#include "lookup_table.hpp"
+#include "interface_query.hpp"
class Direct3D8 : public IUnknown
{
@@ -475,6 +475,3 @@ class Direct3DIndexBuffer8 : public Direct3DResource8, public AddressLookupTable
#ifndef D3D8TO9NOLOG
extern std::ofstream LOG;
#endif
-
-REFIID ConvertREFIID(REFIID riid);
-void genericQueryInterface(REFIID riid, LPVOID *ppvObj, Direct3DDevice8* pDevice);
diff --git a/source/d3d8to9_base.cpp b/source/d3d8to9_base.cpp
index 3236fe1..45311ab 100644
--- a/source/d3d8to9_base.cpp
+++ b/source/d3d8to9_base.cpp
@@ -13,18 +13,14 @@ static const D3DFORMAT AdapterFormats[] = {
D3DFMT_A1R5G5B5
};
-// IDirect3D8
Direct3D8::Direct3D8(IDirect3D9 *ProxyInterface) :
ProxyInterface(ProxyInterface)
{
D3DDISPLAYMODE pMode;
CurrentAdapterCount = ProxyInterface->GetAdapterCount();
-
if (CurrentAdapterCount > MaxAdapters)
- {
CurrentAdapterCount = MaxAdapters;
- }
for (UINT Adapter = 0; Adapter < CurrentAdapterCount; Adapter++)
{
@@ -48,15 +44,12 @@ Direct3D8::~Direct3D8()
HRESULT STDMETHODCALLTYPE Direct3D8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
- {
return E_POINTER;
- }
if (riid == __uuidof(this) ||
riid == __uuidof(IUnknown))
{
AddRef();
-
*ppvObj = this;
return S_OK;
@@ -73,9 +66,7 @@ ULONG STDMETHODCALLTYPE Direct3D8::Release()
const ULONG LastRefCount = ProxyInterface->Release();
if (LastRefCount == 0)
- {
delete this;
- }
return LastRefCount;
}
@@ -91,9 +82,7 @@ UINT STDMETHODCALLTYPE Direct3D8::GetAdapterCount()
HRESULT STDMETHODCALLTYPE Direct3D8::GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8 *pIdentifier)
{
if (pIdentifier == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
D3DADAPTER_IDENTIFIER9 AdapterIndentifier;
@@ -107,11 +96,8 @@ HRESULT STDMETHODCALLTYPE Direct3D8::GetAdapterIdentifier(UINT Adapter, DWORD Fl
}
const HRESULT hr = ProxyInterface->GetAdapterIdentifier(Adapter, Flags, &AdapterIndentifier);
-
if (FAILED(hr))
- {
return hr;
- }
ConvertAdapterIdentifier(AdapterIndentifier, *pIdentifier);
@@ -124,9 +110,7 @@ UINT STDMETHODCALLTYPE Direct3D8::GetAdapterModeCount(UINT Adapter)
HRESULT STDMETHODCALLTYPE Direct3D8::EnumAdapterModes(UINT Adapter, UINT Mode, D3DDISPLAYMODE *pMode)
{
if (pMode == nullptr || !(Adapter < CurrentAdapterCount && Mode < CurrentAdapterModeCount[Adapter]))
- {
return D3DERR_INVALIDCALL;
- }
pMode->Format = CurrentAdapterModes[Adapter].at(Mode).Format;
pMode->Height = CurrentAdapterModes[Adapter].at(Mode).Height;
@@ -145,10 +129,14 @@ HRESULT STDMETHODCALLTYPE Direct3D8::CheckDeviceType(UINT Adapter, D3DDEVTYPE Ch
}
HRESULT STDMETHODCALLTYPE Direct3D8::CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat)
{
- if (CheckFormat == D3DFMT_UYVY || CheckFormat == D3DFMT_YUY2 || CheckFormat == MAKEFOURCC('Y', 'V', '1', '2') || CheckFormat == MAKEFOURCC('N', 'V', '1', '2'))
+ if (CheckFormat == D3DFMT_UYVY ||
+ CheckFormat == D3DFMT_YUY2 ||
+ CheckFormat == MAKEFOURCC('Y', 'V', '1', '2') ||
+ CheckFormat == MAKEFOURCC('N', 'V', '1', '2'))
{
return D3DERR_NOTAVAILABLE;
}
+
return ProxyInterface->CheckDeviceFormat(Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
}
HRESULT STDMETHODCALLTYPE Direct3D8::CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType)
@@ -162,18 +150,13 @@ HRESULT STDMETHODCALLTYPE Direct3D8::CheckDepthStencilMatch(UINT Adapter, D3DDEV
HRESULT STDMETHODCALLTYPE Direct3D8::GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8 *pCaps)
{
if (pCaps == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
D3DCAPS9 DeviceCaps;
const HRESULT hr = ProxyInterface->GetDeviceCaps(Adapter, DeviceType, &DeviceCaps);
-
if (FAILED(hr))
- {
return hr;
- }
ConvertCaps(DeviceCaps, *pCaps);
@@ -190,9 +173,7 @@ HRESULT STDMETHODCALLTYPE Direct3D8::CreateDevice(UINT Adapter, D3DDEVTYPE Devic
#endif
if (pPresentationParameters == nullptr || ppReturnedDeviceInterface == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppReturnedDeviceInterface = nullptr;
@@ -216,12 +197,9 @@ HRESULT STDMETHODCALLTYPE Direct3D8::CreateDevice(UINT Adapter, D3DDEVTYPE Devic
IDirect3DDevice9 *DeviceInterface = nullptr;
- HRESULT hr = ProxyInterface->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, &PresentParams, &DeviceInterface);
-
+ const HRESULT hr = ProxyInterface->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, &PresentParams, &DeviceInterface);
if (FAILED(hr))
- {
return hr;
- }
*ppReturnedDeviceInterface = new Direct3DDevice8(this, DeviceInterface, (PresentParams.Flags & D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL) != 0);
diff --git a/source/d3d8to9_device.cpp b/source/d3d8to9_device.cpp
index 718ea7f..3ea7182 100644
--- a/source/d3d8to9_device.cpp
+++ b/source/d3d8to9_device.cpp
@@ -14,7 +14,6 @@ struct VertexShaderInfo
IDirect3DVertexDeclaration9 *Declaration;
};
-// IDirect3DDevice8
Direct3DDevice8::Direct3DDevice8(Direct3D8 *d3d, IDirect3DDevice9 *ProxyInterface, BOOL EnableZBufferDiscarding) :
D3D(d3d), ProxyInterface(ProxyInterface), ZBufferDiscarding(EnableZBufferDiscarding)
{
@@ -29,26 +28,20 @@ Direct3DDevice8::~Direct3DDevice8()
HRESULT STDMETHODCALLTYPE Direct3DDevice8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
- {
return E_POINTER;
- }
if (riid == __uuidof(this) ||
riid == __uuidof(IUnknown))
{
AddRef();
-
*ppvObj = this;
return S_OK;
}
- HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
-
+ const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
- {
- genericQueryInterface(riid, ppvObj, this);
- }
+ GenericQueryInterface(riid, ppvObj, this);
return hr;
}
@@ -61,9 +54,7 @@ ULONG STDMETHODCALLTYPE Direct3DDevice8::Release()
ULONG LastRefCount = ProxyInterface->Release();
if (LastRefCount == 0)
- {
delete this;
- }
return LastRefCount;
}
@@ -85,12 +76,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::ResourceManagerDiscardBytes(DWORD Byt
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetDirect3D(Direct3D8 **ppD3D8)
{
if (ppD3D8 == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
D3D->AddRef();
-
*ppD3D8 = D3D;
return D3D_OK;
@@ -98,18 +86,13 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetDirect3D(Direct3D8 **ppD3D8)
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetDeviceCaps(D3DCAPS8 *pCaps)
{
if (pCaps == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
D3DCAPS9 DeviceCaps;
const HRESULT hr = ProxyInterface->GetDeviceCaps(&DeviceCaps);
-
if (FAILED(hr))
- {
return hr;
- }
ConvertCaps(DeviceCaps, *pCaps);
@@ -126,9 +109,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetCreationParameters(D3DDEVICE_CREAT
HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetCursorProperties(UINT XHotSpot, UINT YHotSpot, Direct3DSurface8 *pCursorBitmap)
{
if (pCursorBitmap == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
return ProxyInterface->SetCursorProperties(XHotSpot, YHotSpot, pCursorBitmap->GetProxyInterface());
}
@@ -147,9 +128,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateAdditionalSwapChain(D3DPRESENT_
#endif
if (pPresentationParameters == nullptr || ppSwapChain == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppSwapChain = nullptr;
@@ -177,11 +156,8 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateAdditionalSwapChain(D3DPRESENT_
IDirect3DSwapChain9 *SwapChainInterface = nullptr;
const HRESULT hr = ProxyInterface->CreateAdditionalSwapChain(&PresentParams, &SwapChainInterface);
-
if (FAILED(hr))
- {
return hr;
- }
*ppSwapChain = new Direct3DSwapChain8(this, SwapChainInterface);
@@ -194,9 +170,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::Reset(D3DPRESENT_PARAMETERS8 *pPresen
#endif
if (pPresentationParameters == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
pCurrentRenderTarget = nullptr;
@@ -232,20 +206,15 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::Present(const RECT *pSourceRect, cons
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, Direct3DSurface8 **ppBackBuffer)
{
if (ppBackBuffer == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppBackBuffer = nullptr;
IDirect3DSurface9 *SurfaceInterface = nullptr;
const HRESULT hr = ProxyInterface->GetBackBuffer(0, iBackBuffer, Type, &SurfaceInterface);
-
if (FAILED(hr))
- {
return hr;
- }
*ppBackBuffer = ProxyAddressLookupTable->FindAddress(SurfaceInterface);
@@ -266,9 +235,7 @@ void STDMETHODCALLTYPE Direct3DDevice8::GetGammaRamp(D3DGAMMARAMP *pRamp)
HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, Direct3DTexture8 **ppTexture)
{
if (ppTexture == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppTexture = nullptr;
@@ -291,11 +258,8 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateTexture(UINT Width, UINT Height
IDirect3DTexture9 *TextureInterface = nullptr;
const HRESULT hr = ProxyInterface->CreateTexture(Width, Height, Levels, Usage, Format, Pool, &TextureInterface, nullptr);
-
if (FAILED(hr))
- {
return hr;
- }
*ppTexture = new Direct3DTexture8(this, TextureInterface);
@@ -304,20 +268,15 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateTexture(UINT Width, UINT Height
HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, Direct3DVolumeTexture8 **ppVolumeTexture)
{
if (ppVolumeTexture == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppVolumeTexture = nullptr;
IDirect3DVolumeTexture9 *TextureInterface = nullptr;
const HRESULT hr = ProxyInterface->CreateVolumeTexture(Width, Height, Depth, Levels, Usage, Format, Pool, &TextureInterface, nullptr);
-
if (FAILED(hr))
- {
return hr;
- }
*ppVolumeTexture = new Direct3DVolumeTexture8(this, TextureInterface);
@@ -326,20 +285,15 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateVolumeTexture(UINT Width, UINT
HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, Direct3DCubeTexture8 **ppCubeTexture)
{
if (ppCubeTexture == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppCubeTexture = nullptr;
IDirect3DCubeTexture9 *TextureInterface = nullptr;
const HRESULT hr = ProxyInterface->CreateCubeTexture(EdgeLength, Levels, Usage, Format, Pool, &TextureInterface, nullptr);
-
if (FAILED(hr))
- {
return hr;
- }
*ppCubeTexture = new Direct3DCubeTexture8(this, TextureInterface);
@@ -348,20 +302,15 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateCubeTexture(UINT EdgeLength, UI
HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateVertexBuffer(UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, Direct3DVertexBuffer8 **ppVertexBuffer)
{
if (ppVertexBuffer == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppVertexBuffer = nullptr;
IDirect3DVertexBuffer9 *BufferInterface = nullptr;
const HRESULT hr = ProxyInterface->CreateVertexBuffer(Length, Usage, FVF, Pool, &BufferInterface, nullptr);
-
if (FAILED(hr))
- {
return hr;
- }
*ppVertexBuffer = new Direct3DVertexBuffer8(this, BufferInterface);
@@ -370,20 +319,15 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateVertexBuffer(UINT Length, DWORD
HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, Direct3DIndexBuffer8 **ppIndexBuffer)
{
if (ppIndexBuffer == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppIndexBuffer = nullptr;
IDirect3DIndexBuffer9 *BufferInterface = nullptr;
const HRESULT hr = ProxyInterface->CreateIndexBuffer(Length, Usage, Format, Pool, &BufferInterface, nullptr);
-
if (FAILED(hr))
- {
return hr;
- }
*ppIndexBuffer = new Direct3DIndexBuffer8(this, BufferInterface);
@@ -392,9 +336,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateIndexBuffer(UINT Length, DWORD
HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateRenderTarget(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, Direct3DSurface8 **ppSurface)
{
if (ppSurface == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppSurface = nullptr;
@@ -412,12 +354,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateRenderTarget(UINT Width, UINT H
IDirect3DSurface9 *SurfaceInterface = nullptr;
- HRESULT hr = ProxyInterface->CreateRenderTarget(Width, Height, Format, MultiSample, QualityLevels, Lockable, &SurfaceInterface, nullptr);
-
+ const HRESULT hr = ProxyInterface->CreateRenderTarget(Width, Height, Format, MultiSample, QualityLevels, Lockable, &SurfaceInterface, nullptr);
if (FAILED(hr))
- {
return hr;
- }
*ppSurface = new Direct3DSurface8(this, SurfaceInterface);
@@ -426,9 +365,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateRenderTarget(UINT Width, UINT H
HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, Direct3DSurface8 **ppSurface)
{
if (ppSurface == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppSurface = nullptr;
@@ -446,12 +383,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateDepthStencilSurface(UINT Width,
IDirect3DSurface9 *SurfaceInterface = nullptr;
- HRESULT hr = ProxyInterface->CreateDepthStencilSurface(Width, Height, Format, MultiSample, QualityLevels, ZBufferDiscarding, &SurfaceInterface, nullptr);
-
+ const HRESULT hr = ProxyInterface->CreateDepthStencilSurface(Width, Height, Format, MultiSample, QualityLevels, ZBufferDiscarding, &SurfaceInterface, nullptr);
if (FAILED(hr))
- {
return hr;
- }
*ppSurface = new Direct3DSurface8(this, SurfaceInterface);
@@ -464,9 +398,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateImageSurface(UINT Width, UINT H
#endif
if (ppSurface == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppSurface = nullptr;
@@ -475,7 +407,6 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateImageSurface(UINT Width, UINT H
#ifndef D3D8TO9NOLOG
LOG << "> Replacing format 'D3DFMT_R8G8B8' with 'D3DFMT_X8R8G8B8' ..." << std::endl;
#endif
-
Format = D3DFMT_X8R8G8B8;
}
@@ -488,7 +419,6 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateImageSurface(UINT Width, UINT H
#ifndef D3D8TO9NOLOG
LOG << "> 'IDirect3DDevice9::CreateOffscreenPlainSurface' failed with error code " << std::hex << hr << std::dec << "!" << std::endl;
#endif
-
return hr;
}
@@ -499,25 +429,19 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateImageSurface(UINT Width, UINT H
HRESULT STDMETHODCALLTYPE Direct3DDevice8::CopyRects(Direct3DSurface8 *pSourceSurface, const RECT *pSourceRectsArray, UINT cRects, Direct3DSurface8 *pDestinationSurface, const POINT *pDestPointsArray)
{
if (pSourceSurface == nullptr || pDestinationSurface == nullptr || pSourceSurface == pDestinationSurface)
- {
return D3DERR_INVALIDCALL;
- }
D3DSURFACE_DESC SourceDesc, DestinationDesc;
pSourceSurface->GetProxyInterface()->GetDesc(&SourceDesc);
pDestinationSurface->GetProxyInterface()->GetDesc(&DestinationDesc);
if (SourceDesc.Format != DestinationDesc.Format)
- {
return D3DERR_INVALIDCALL;
- }
HRESULT hr = D3DERR_INVALIDCALL;
if (cRects == 0)
- {
- cRects = 1;
- }
+ cRects = 1;
for (UINT i = 0; i < cRects; i++)
{
@@ -591,28 +515,26 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CopyRects(Direct3DSurface8 *pSourceSu
HRESULT STDMETHODCALLTYPE Direct3DDevice8::UpdateTexture(Direct3DBaseTexture8 *pSourceTexture, Direct3DBaseTexture8 *pDestinationTexture)
{
if (pSourceTexture == nullptr || pDestinationTexture == nullptr || pSourceTexture->GetType() != pDestinationTexture->GetType())
- {
return D3DERR_INVALIDCALL;
- }
IDirect3DBaseTexture9 *SourceBaseTextureInterface, *DestinationBaseTextureInterface;
switch (pSourceTexture->GetType())
{
- case D3DRTYPE_TEXTURE:
- SourceBaseTextureInterface = static_cast(pSourceTexture)->GetProxyInterface();
- DestinationBaseTextureInterface = static_cast(pDestinationTexture)->GetProxyInterface();
- break;
- case D3DRTYPE_VOLUMETEXTURE:
- SourceBaseTextureInterface = static_cast(pSourceTexture)->GetProxyInterface();
- DestinationBaseTextureInterface = static_cast(pDestinationTexture)->GetProxyInterface();
- break;
- case D3DRTYPE_CUBETEXTURE:
- SourceBaseTextureInterface = static_cast(pSourceTexture)->GetProxyInterface();
- DestinationBaseTextureInterface = static_cast(pDestinationTexture)->GetProxyInterface();
- break;
- default:
- return D3DERR_INVALIDCALL;
+ case D3DRTYPE_TEXTURE:
+ SourceBaseTextureInterface = static_cast(pSourceTexture)->GetProxyInterface();
+ DestinationBaseTextureInterface = static_cast(pDestinationTexture)->GetProxyInterface();
+ break;
+ case D3DRTYPE_VOLUMETEXTURE:
+ SourceBaseTextureInterface = static_cast(pSourceTexture)->GetProxyInterface();
+ DestinationBaseTextureInterface = static_cast(pDestinationTexture)->GetProxyInterface();
+ break;
+ case D3DRTYPE_CUBETEXTURE:
+ SourceBaseTextureInterface = static_cast(pSourceTexture)->GetProxyInterface();
+ DestinationBaseTextureInterface = static_cast(pDestinationTexture)->GetProxyInterface();
+ break;
+ default:
+ return D3DERR_INVALIDCALL;
}
return ProxyInterface->UpdateTexture(SourceBaseTextureInterface, DestinationBaseTextureInterface);
@@ -620,9 +542,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::UpdateTexture(Direct3DBaseTexture8 *p
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetFrontBuffer(Direct3DSurface8 *pDestSurface)
{
if (pDestSurface == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
return ProxyInterface->GetFrontBufferData(0, pDestSurface->GetProxyInterface());
}
@@ -633,11 +553,8 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetRenderTarget(Direct3DSurface8 *pRe
if (pRenderTarget != nullptr)
{
hr = ProxyInterface->SetRenderTarget(0, pRenderTarget->GetProxyInterface());
-
if (FAILED(hr))
- {
return hr;
- }
pCurrentRenderTarget = pRenderTarget->GetProxyInterface();
}
@@ -645,11 +562,8 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetRenderTarget(Direct3DSurface8 *pRe
if (pNewZStencil != nullptr)
{
hr = ProxyInterface->SetDepthStencilSurface(pNewZStencil->GetProxyInterface());
-
if (FAILED(hr))
- {
return hr;
- }
}
else
{
@@ -661,18 +575,13 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetRenderTarget(Direct3DSurface8 *pRe
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetRenderTarget(Direct3DSurface8 **ppRenderTarget)
{
if (ppRenderTarget == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
IDirect3DSurface9 *SurfaceInterface = nullptr;
const HRESULT hr = ProxyInterface->GetRenderTarget(0, &SurfaceInterface);
-
if (FAILED(hr))
- {
return hr;
- }
pCurrentRenderTarget = SurfaceInterface;
@@ -683,18 +592,13 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetRenderTarget(Direct3DSurface8 **pp
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetDepthStencilSurface(Direct3DSurface8 **ppZStencilSurface)
{
if (ppZStencilSurface == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
IDirect3DSurface9 *SurfaceInterface = nullptr;
const HRESULT hr = ProxyInterface->GetDepthStencilSurface(&SurfaceInterface);
-
if (FAILED(hr))
- {
return hr;
- }
*ppZStencilSurface = ProxyAddressLookupTable->FindAddress(SurfaceInterface);
@@ -731,9 +635,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetViewport(const D3DVIEWPORT8 *pView
D3DSURFACE_DESC Desc;
if (SUCCEEDED(pCurrentRenderTarget->GetDesc(&Desc)) && (pViewport->Height > Desc.Height || pViewport->Width > Desc.Width))
- {
return D3DERR_INVALIDCALL;
- }
}
return ProxyInterface->SetViewport(pViewport);
@@ -768,14 +670,16 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetLightEnable(DWORD Index, BOOL *pEn
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetClipPlane(DWORD Index, const float *pPlane)
{
- if (pPlane == nullptr || Index >= MAX_CLIP_PLANES) return D3DERR_INVALIDCALL;
+ if (pPlane == nullptr || Index >= MAX_CLIP_PLANES)
+ return D3DERR_INVALIDCALL;
memcpy(StoredClipPlanes[Index], pPlane, sizeof(StoredClipPlanes[0]));
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetClipPlane(DWORD Index, float *pPlane)
{
- if (pPlane == nullptr || Index >= MAX_CLIP_PLANES) return D3DERR_INVALIDCALL;
+ if (pPlane == nullptr || Index >= MAX_CLIP_PLANES)
+ return D3DERR_INVALIDCALL;
memcpy(pPlane, StoredClipPlanes[Index], sizeof(StoredClipPlanes[0]));
return D3D_OK;
@@ -787,60 +691,56 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetRenderState(D3DRENDERSTATETYPE Sta
switch (static_cast(State))
{
- case D3DRS_ZVISIBLE:
- return D3DERR_INVALIDCALL;
- case D3DRS_PATCHSEGMENTS:
- case D3DRS_LINEPATTERN:
- case D3DRS_SOFTWAREVERTEXPROCESSING:
- return D3D_OK;
- case D3DRS_EDGEANTIALIAS:
- return ProxyInterface->SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, Value);
- case D3DRS_CLIPPLANEENABLE:
- hr = ProxyInterface->SetRenderState(State, Value);
- if (SUCCEEDED(hr))
- {
- ClipPlaneRenderState = Value;
- }
- return hr;
- case D3DRS_ZBIAS:
- Biased = static_cast(Value) * -0.000005f;
- Value = *reinterpret_cast(&Biased);
- State = D3DRS_DEPTHBIAS;
- default:
- return ProxyInterface->SetRenderState(State, Value);
+ case D3DRS_ZVISIBLE:
+ return D3DERR_INVALIDCALL;
+ case D3DRS_PATCHSEGMENTS:
+ case D3DRS_LINEPATTERN:
+ case D3DRS_SOFTWAREVERTEXPROCESSING:
+ return D3D_OK;
+ case D3DRS_EDGEANTIALIAS:
+ return ProxyInterface->SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, Value);
+ case D3DRS_CLIPPLANEENABLE:
+ hr = ProxyInterface->SetRenderState(State, Value);
+ if (SUCCEEDED(hr))
+ ClipPlaneRenderState = Value;
+ return hr;
+ case D3DRS_ZBIAS:
+ Biased = static_cast(Value) * -0.000005f;
+ Value = *reinterpret_cast(&Biased);
+ State = D3DRS_DEPTHBIAS;
+ default:
+ return ProxyInterface->SetRenderState(State, Value);
}
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetRenderState(D3DRENDERSTATETYPE State, DWORD *pValue)
{
if (pValue == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
HRESULT hr;
*pValue = 0;
switch (static_cast(State))
{
- case D3DRS_ZVISIBLE:
- return D3DERR_INVALIDCALL;
- case D3DRS_LINEPATTERN:
- *pValue = 0;
- return D3D_OK;
- case D3DRS_EDGEANTIALIAS:
- return ProxyInterface->GetRenderState(D3DRS_ANTIALIASEDLINEENABLE, pValue);
- case D3DRS_ZBIAS:
- hr = ProxyInterface->GetRenderState(D3DRS_DEPTHBIAS, pValue);
- *pValue = static_cast(*reinterpret_cast(pValue) * -500000.0f);
- return hr;
- case D3DRS_SOFTWAREVERTEXPROCESSING:
- *pValue = ProxyInterface->GetSoftwareVertexProcessing();
- return D3D_OK;
- case D3DRS_PATCHSEGMENTS:
- *pValue = 1;
- return D3D_OK;
- default:
- return ProxyInterface->GetRenderState(State, pValue);
+ case D3DRS_ZVISIBLE:
+ return D3DERR_INVALIDCALL;
+ case D3DRS_LINEPATTERN:
+ *pValue = 0;
+ return D3D_OK;
+ case D3DRS_EDGEANTIALIAS:
+ return ProxyInterface->GetRenderState(D3DRS_ANTIALIASEDLINEENABLE, pValue);
+ case D3DRS_ZBIAS:
+ hr = ProxyInterface->GetRenderState(D3DRS_DEPTHBIAS, pValue);
+ *pValue = static_cast(*reinterpret_cast(pValue) * -500000.0f);
+ return hr;
+ case D3DRS_SOFTWAREVERTEXPROCESSING:
+ *pValue = ProxyInterface->GetSoftwareVertexProcessing();
+ return D3D_OK;
+ case D3DRS_PATCHSEGMENTS:
+ *pValue = 1;
+ return D3D_OK;
+ default:
+ return ProxyInterface->GetRenderState(State, pValue);
}
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::BeginStateBlock()
@@ -850,36 +750,28 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::BeginStateBlock()
HRESULT STDMETHODCALLTYPE Direct3DDevice8::EndStateBlock(DWORD *pToken)
{
if (pToken == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
return ProxyInterface->EndStateBlock(reinterpret_cast(pToken));
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::ApplyStateBlock(DWORD Token)
{
if (Token == 0)
- {
return D3DERR_INVALIDCALL;
- }
return reinterpret_cast(Token)->Apply();
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::CaptureStateBlock(DWORD Token)
{
if (Token == 0)
- {
return D3DERR_INVALIDCALL;
- }
return reinterpret_cast(Token)->Capture();
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::DeleteStateBlock(DWORD Token)
{
if (Token == 0)
- {
return D3DERR_INVALIDCALL;
- }
reinterpret_cast(Token)->Release();
@@ -892,9 +784,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateStateBlock(D3DSTATEBLOCKTYPE Ty
#endif
if (pToken == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
return ProxyInterface->CreateStateBlock(Type, reinterpret_cast(pToken));
}
@@ -909,20 +799,15 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetClipStatus(D3DCLIPSTATUS8 *pClipSt
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetTexture(DWORD Stage, Direct3DBaseTexture8 **ppTexture)
{
if (ppTexture == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppTexture = nullptr;
IDirect3DBaseTexture9 *BaseTextureInterface = nullptr;
const HRESULT hr = ProxyInterface->GetTexture(Stage, &BaseTextureInterface);
-
if (FAILED(hr))
- {
return hr;
- }
if (BaseTextureInterface != nullptr)
{
@@ -932,20 +817,20 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetTexture(DWORD Stage, Direct3DBaseT
switch (BaseTextureInterface->GetType())
{
- case D3DRTYPE_TEXTURE:
- BaseTextureInterface->QueryInterface(IID_PPV_ARGS(&TextureInterface));
- *ppTexture = ProxyAddressLookupTable->FindAddress(TextureInterface);
- break;
- case D3DRTYPE_VOLUMETEXTURE:
- BaseTextureInterface->QueryInterface(IID_PPV_ARGS(&VolumeTextureInterface));
- *ppTexture = ProxyAddressLookupTable->FindAddress(VolumeTextureInterface);
- break;
- case D3DRTYPE_CUBETEXTURE:
- BaseTextureInterface->QueryInterface(IID_PPV_ARGS(&CubeTextureInterface));
- *ppTexture = ProxyAddressLookupTable->FindAddress(CubeTextureInterface);
- break;
- default:
- return D3DERR_INVALIDCALL;
+ case D3DRTYPE_TEXTURE:
+ BaseTextureInterface->QueryInterface(IID_PPV_ARGS(&TextureInterface));
+ *ppTexture = ProxyAddressLookupTable->FindAddress(TextureInterface);
+ break;
+ case D3DRTYPE_VOLUMETEXTURE:
+ BaseTextureInterface->QueryInterface(IID_PPV_ARGS(&VolumeTextureInterface));
+ *ppTexture = ProxyAddressLookupTable->FindAddress(VolumeTextureInterface);
+ break;
+ case D3DRTYPE_CUBETEXTURE:
+ BaseTextureInterface->QueryInterface(IID_PPV_ARGS(&CubeTextureInterface));
+ *ppTexture = ProxyAddressLookupTable->FindAddress(CubeTextureInterface);
+ break;
+ default:
+ return D3DERR_INVALIDCALL;
}
}
@@ -954,25 +839,23 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetTexture(DWORD Stage, Direct3DBaseT
HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetTexture(DWORD Stage, Direct3DBaseTexture8 *pTexture)
{
if (pTexture == nullptr)
- {
return ProxyInterface->SetTexture(Stage, nullptr);
- }
IDirect3DBaseTexture9 *BaseTextureInterface;
switch (pTexture->GetType())
{
- case D3DRTYPE_TEXTURE:
- BaseTextureInterface = static_cast(pTexture)->GetProxyInterface();
- break;
- case D3DRTYPE_VOLUMETEXTURE:
- BaseTextureInterface = static_cast(pTexture)->GetProxyInterface();
- break;
- case D3DRTYPE_CUBETEXTURE:
- BaseTextureInterface = static_cast(pTexture)->GetProxyInterface();
- break;
- default:
- return D3DERR_INVALIDCALL;
+ case D3DRTYPE_TEXTURE:
+ BaseTextureInterface = static_cast(pTexture)->GetProxyInterface();
+ break;
+ case D3DRTYPE_VOLUMETEXTURE:
+ BaseTextureInterface = static_cast(pTexture)->GetProxyInterface();
+ break;
+ case D3DRTYPE_CUBETEXTURE:
+ BaseTextureInterface = static_cast(pTexture)->GetProxyInterface();
+ break;
+ default:
+ return D3DERR_INVALIDCALL;
}
return ProxyInterface->SetTexture(Stage, BaseTextureInterface);
@@ -981,56 +864,56 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetTextureStageState(DWORD Stage, D3D
{
switch (static_cast(Type))
{
- case D3DTSS_ADDRESSU:
- return ProxyInterface->GetSamplerState(Stage, D3DSAMP_ADDRESSU, pValue);
- case D3DTSS_ADDRESSV:
- return ProxyInterface->GetSamplerState(Stage, D3DSAMP_ADDRESSV, pValue);
- case D3DTSS_ADDRESSW:
- return ProxyInterface->GetSamplerState(Stage, D3DSAMP_ADDRESSW, pValue);
- case D3DTSS_BORDERCOLOR:
- return ProxyInterface->GetSamplerState(Stage, D3DSAMP_BORDERCOLOR, pValue);
- case D3DTSS_MAGFILTER:
- return ProxyInterface->GetSamplerState(Stage, D3DSAMP_MAGFILTER, pValue);
- case D3DTSS_MINFILTER:
- return ProxyInterface->GetSamplerState(Stage, D3DSAMP_MINFILTER, pValue);
- case D3DTSS_MIPFILTER:
- return ProxyInterface->GetSamplerState(Stage, D3DSAMP_MIPFILTER, pValue);
- case D3DTSS_MIPMAPLODBIAS:
- return ProxyInterface->GetSamplerState(Stage, D3DSAMP_MIPMAPLODBIAS, pValue);
- case D3DTSS_MAXMIPLEVEL:
- return ProxyInterface->GetSamplerState(Stage, D3DSAMP_MAXMIPLEVEL, pValue);
- case D3DTSS_MAXANISOTROPY:
- return ProxyInterface->GetSamplerState(Stage, D3DSAMP_MAXANISOTROPY, pValue);
- default:
- return ProxyInterface->GetTextureStageState(Stage, Type, pValue);
+ case D3DTSS_ADDRESSU:
+ return ProxyInterface->GetSamplerState(Stage, D3DSAMP_ADDRESSU, pValue);
+ case D3DTSS_ADDRESSV:
+ return ProxyInterface->GetSamplerState(Stage, D3DSAMP_ADDRESSV, pValue);
+ case D3DTSS_ADDRESSW:
+ return ProxyInterface->GetSamplerState(Stage, D3DSAMP_ADDRESSW, pValue);
+ case D3DTSS_BORDERCOLOR:
+ return ProxyInterface->GetSamplerState(Stage, D3DSAMP_BORDERCOLOR, pValue);
+ case D3DTSS_MAGFILTER:
+ return ProxyInterface->GetSamplerState(Stage, D3DSAMP_MAGFILTER, pValue);
+ case D3DTSS_MINFILTER:
+ return ProxyInterface->GetSamplerState(Stage, D3DSAMP_MINFILTER, pValue);
+ case D3DTSS_MIPFILTER:
+ return ProxyInterface->GetSamplerState(Stage, D3DSAMP_MIPFILTER, pValue);
+ case D3DTSS_MIPMAPLODBIAS:
+ return ProxyInterface->GetSamplerState(Stage, D3DSAMP_MIPMAPLODBIAS, pValue);
+ case D3DTSS_MAXMIPLEVEL:
+ return ProxyInterface->GetSamplerState(Stage, D3DSAMP_MAXMIPLEVEL, pValue);
+ case D3DTSS_MAXANISOTROPY:
+ return ProxyInterface->GetSamplerState(Stage, D3DSAMP_MAXANISOTROPY, pValue);
+ default:
+ return ProxyInterface->GetTextureStageState(Stage, Type, pValue);
}
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
{
switch (static_cast(Type))
{
- case D3DTSS_ADDRESSU:
- return ProxyInterface->SetSamplerState(Stage, D3DSAMP_ADDRESSU, Value);
- case D3DTSS_ADDRESSV:
- return ProxyInterface->SetSamplerState(Stage, D3DSAMP_ADDRESSV, Value);
- case D3DTSS_ADDRESSW:
- return ProxyInterface->SetSamplerState(Stage, D3DSAMP_ADDRESSW, Value);
- case D3DTSS_BORDERCOLOR:
- return ProxyInterface->SetSamplerState(Stage, D3DSAMP_BORDERCOLOR, Value);
- case D3DTSS_MAGFILTER:
- return ProxyInterface->SetSamplerState(Stage, D3DSAMP_MAGFILTER, Value);
- case D3DTSS_MINFILTER:
- return ProxyInterface->SetSamplerState(Stage, D3DSAMP_MINFILTER, Value);
- case D3DTSS_MIPFILTER:
- return ProxyInterface->SetSamplerState(Stage, D3DSAMP_MIPFILTER, Value);
- case D3DTSS_MIPMAPLODBIAS:
- return ProxyInterface->SetSamplerState(Stage, D3DSAMP_MIPMAPLODBIAS, Value);
- case D3DTSS_MAXMIPLEVEL:
- return ProxyInterface->SetSamplerState(Stage, D3DSAMP_MAXMIPLEVEL, Value);
- case D3DTSS_MAXANISOTROPY:
- return ProxyInterface->SetSamplerState(Stage, D3DSAMP_MAXANISOTROPY, Value);
- default:
- return ProxyInterface->SetTextureStageState(Stage, Type, Value);
+ case D3DTSS_ADDRESSU:
+ return ProxyInterface->SetSamplerState(Stage, D3DSAMP_ADDRESSU, Value);
+ case D3DTSS_ADDRESSV:
+ return ProxyInterface->SetSamplerState(Stage, D3DSAMP_ADDRESSV, Value);
+ case D3DTSS_ADDRESSW:
+ return ProxyInterface->SetSamplerState(Stage, D3DSAMP_ADDRESSW, Value);
+ case D3DTSS_BORDERCOLOR:
+ return ProxyInterface->SetSamplerState(Stage, D3DSAMP_BORDERCOLOR, Value);
+ case D3DTSS_MAGFILTER:
+ return ProxyInterface->SetSamplerState(Stage, D3DSAMP_MAGFILTER, Value);
+ case D3DTSS_MINFILTER:
+ return ProxyInterface->SetSamplerState(Stage, D3DSAMP_MINFILTER, Value);
+ case D3DTSS_MIPFILTER:
+ return ProxyInterface->SetSamplerState(Stage, D3DSAMP_MIPFILTER, Value);
+ case D3DTSS_MIPMAPLODBIAS:
+ return ProxyInterface->SetSamplerState(Stage, D3DSAMP_MIPMAPLODBIAS, Value);
+ case D3DTSS_MAXMIPLEVEL:
+ return ProxyInterface->SetSamplerState(Stage, D3DSAMP_MAXMIPLEVEL, Value);
+ case D3DTSS_MAXANISOTROPY:
+ return ProxyInterface->SetSamplerState(Stage, D3DSAMP_MAXANISOTROPY, Value);
+ default:
+ return ProxyInterface->SetTextureStageState(Stage, Type, Value);
}
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::ValidateDevice(DWORD *pNumPasses)
@@ -1052,33 +935,29 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetInfo(DWORD DevInfoID, void *pDevIn
HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetPaletteEntries(UINT PaletteNumber, const PALETTEENTRY *pEntries)
{
if (pEntries == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
+
return ProxyInterface->SetPaletteEntries(PaletteNumber, pEntries);
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetPaletteEntries(UINT PaletteNumber, PALETTEENTRY *pEntries)
{
if (pEntries == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
+
return ProxyInterface->GetPaletteEntries(PaletteNumber, pEntries);
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetCurrentTexturePalette(UINT PaletteNumber)
{
if (!PaletteFlag)
- {
return D3DERR_INVALIDCALL;
- }
+
return ProxyInterface->SetCurrentTexturePalette(PaletteNumber);
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetCurrentTexturePalette(UINT *pPaletteNumber)
{
if (!PaletteFlag)
- {
return D3DERR_INVALIDCALL;
- }
+
return ProxyInterface->GetCurrentTexturePalette(pPaletteNumber);
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
@@ -1104,9 +983,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::DrawIndexedPrimitiveUP(D3DPRIMITIVETY
HRESULT STDMETHODCALLTYPE Direct3DDevice8::ProcessVertices(UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, Direct3DVertexBuffer8 *pDestBuffer, DWORD Flags)
{
if (pDestBuffer == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
return ProxyInterface->ProcessVertices(SrcStartIndex, DestIndex, VertexCount, pDestBuffer->GetProxyInterface(), nullptr, Flags);
}
@@ -1119,9 +996,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateVertexShader(const DWORD *pDecl
#endif
if (pDeclaration == nullptr || pHandle == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*pHandle = 0;
@@ -1352,27 +1227,27 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateVertexShader(const DWORD *pDecl
switch (VertexElements[k].Usage)
{
- case D3DDECLUSAGE_POSITION:
- DeclCode += "dcl_position";
- break;
- case D3DDECLUSAGE_BLENDWEIGHT:
- DeclCode += "dcl_blendweight";
- break;
- case D3DDECLUSAGE_BLENDINDICES:
- DeclCode += "dcl_blendindices";
- break;
- case D3DDECLUSAGE_NORMAL:
- DeclCode += "dcl_normal";
- break;
- case D3DDECLUSAGE_PSIZE:
- DeclCode += "dcl_psize";
- break;
- case D3DDECLUSAGE_COLOR:
- DeclCode += "dcl_color";
- break;
- case D3DDECLUSAGE_TEXCOORD:
- DeclCode += "dcl_texcoord";
- break;
+ case D3DDECLUSAGE_POSITION:
+ DeclCode += "dcl_position";
+ break;
+ case D3DDECLUSAGE_BLENDWEIGHT:
+ DeclCode += "dcl_blendweight";
+ break;
+ case D3DDECLUSAGE_BLENDINDICES:
+ DeclCode += "dcl_blendindices";
+ break;
+ case D3DDECLUSAGE_NORMAL:
+ DeclCode += "dcl_normal";
+ break;
+ case D3DDECLUSAGE_PSIZE:
+ DeclCode += "dcl_psize";
+ break;
+ case D3DDECLUSAGE_COLOR:
+ DeclCode += "dcl_color";
+ break;
+ case D3DDECLUSAGE_TEXCOORD:
+ DeclCode += "dcl_texcoord";
+ break;
}
if (VertexElements[k].UsageIndex > 0)
@@ -1502,7 +1377,6 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateVertexShader(const DWORD *pDecl
#ifndef D3D8TO9NOLOG
LOG << "> Failed to reassemble shader:" << std::endl << std::endl << static_cast(ErrorBuffer->GetBufferPointer()) << std::endl;
#endif
-
ErrorBuffer->Release();
}
else
@@ -1546,11 +1420,8 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreateVertexShader(const DWORD *pDecl
#ifndef D3D8TO9NOLOG
LOG << "> 'IDirect3DDevice9::CreateVertexDeclaration' failed with error code " << std::hex << hr << std::dec << "!" << std::endl;
#endif
-
if (ShaderInfo->Shader != nullptr)
- {
ShaderInfo->Shader->Release();
- }
}
}
else
@@ -1594,9 +1465,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetVertexShader(DWORD Handle)
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetVertexShader(DWORD *pHandle)
{
if (pHandle == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
if (CurrentVertexShaderHandle == 0)
{
@@ -1605,33 +1474,24 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetVertexShader(DWORD *pHandle)
else
{
*pHandle = CurrentVertexShaderHandle;
-
return D3D_OK;
}
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::DeleteVertexShader(DWORD Handle)
{
if ((Handle & 0x80000000) == 0)
- {
return D3DERR_INVALIDCALL;
- }
if (CurrentVertexShaderHandle == Handle)
- {
SetVertexShader(0);
- }
const DWORD HandleMagic = Handle << 1;
VertexShaderInfo *const ShaderInfo = reinterpret_cast(HandleMagic);
if (ShaderInfo->Shader != nullptr)
- {
ShaderInfo->Shader->Release();
- }
if (ShaderInfo->Declaration != nullptr)
- {
ShaderInfo->Declaration->Release();
- }
delete ShaderInfo;
@@ -1665,17 +1525,13 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetVertexShaderFunction(DWORD Handle,
#endif
if ((Handle & 0x80000000) == 0)
- {
return D3DERR_INVALIDCALL;
- }
const DWORD HandleMagic = Handle << 1;
IDirect3DVertexShader9 *VertexShaderInterface = reinterpret_cast(HandleMagic)->Shader;
if (VertexShaderInterface == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
#ifndef D3D8TO9NOLOG
LOG << "> Returning translated shader byte code." << std::endl;
@@ -1686,46 +1542,33 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetVertexShaderFunction(DWORD Handle,
HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetStreamSource(UINT StreamNumber, Direct3DVertexBuffer8 *pStreamData, UINT Stride)
{
if (pStreamData == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
return ProxyInterface->SetStreamSource(StreamNumber, pStreamData->GetProxyInterface(), 0, Stride);
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetStreamSource(UINT StreamNumber, Direct3DVertexBuffer8 **ppStreamData, UINT *pStride)
{
if (ppStreamData == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
- else
- {
- *ppStreamData = nullptr;
- }
+
+ *ppStreamData = nullptr;
UINT StreamOffset = 0;
IDirect3DVertexBuffer9 *VertexBufferInterface = nullptr;
const HRESULT hr = ProxyInterface->GetStreamSource(StreamNumber, &VertexBufferInterface, &StreamOffset, pStride);
-
if (FAILED(hr))
- {
return hr;
- }
if (VertexBufferInterface != nullptr)
- {
*ppStreamData = ProxyAddressLookupTable->FindAddress(VertexBufferInterface);
- }
return D3D_OK;
}
HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetIndices(Direct3DIndexBuffer8 *pIndexData, UINT BaseVertexIndex)
{
if (pIndexData == nullptr || BaseVertexIndex > 0x7FFFFFFF)
- {
return D3DERR_INVALIDCALL;
- }
CurrentBaseVertexIndex = static_cast(BaseVertexIndex);
@@ -1734,30 +1577,21 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetIndices(Direct3DIndexBuffer8 *pInd
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetIndices(Direct3DIndexBuffer8 **ppIndexData, UINT *pBaseVertexIndex)
{
if (ppIndexData == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppIndexData = nullptr;
if (pBaseVertexIndex != nullptr)
- {
*pBaseVertexIndex = static_cast(CurrentBaseVertexIndex);
- }
IDirect3DIndexBuffer9 *IntexBufferInterface = nullptr;
const HRESULT hr = ProxyInterface->GetIndices(&IntexBufferInterface);
-
if (FAILED(hr))
- {
return hr;
- }
if (IntexBufferInterface != nullptr)
- {
*ppIndexData = ProxyAddressLookupTable->FindAddress(IntexBufferInterface);
- }
return D3D_OK;
}
@@ -1768,9 +1602,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreatePixelShader(const DWORD *pFunct
#endif
if (pFunction == nullptr || pHandle == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*pHandle = 0;
@@ -1783,7 +1615,6 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreatePixelShader(const DWORD *pFunct
#ifndef D3D8TO9NOLOG
LOG << "> Failed because of version mismatch ('" << std::showbase << std::hex << *pFunction << std::dec << std::noshowbase << "')! Only 'ps_1_x' shaders are supported." << std::endl;
#endif
-
return D3DERR_INVALIDCALL;
}
@@ -1792,16 +1623,13 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreatePixelShader(const DWORD *pFunct
HRESULT hr = D3DERR_INVALIDCALL;
if (D3DXDisassembleShader != nullptr)
- {
hr = D3DXDisassembleShader(pFunction, FALSE, nullptr, &Disassembly);
- }
if (FAILED(hr))
{
#ifndef D3D8TO9NOLOG
LOG << "> Failed to disassemble shader with error code " << std::hex << hr << std::dec << "!" << std::endl;
#endif
-
return hr;
}
@@ -1869,10 +1697,10 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreatePixelShader(const DWORD *pFunct
std::regex("( .*\\n) \\+ (...)(_[_satxd248]*|) (r[0-9])([\\.wxyz]*), (1?-?[crtv][0-9][\\.wxyz_abdis2]*, )?(1?-?[crtv][0-9][\\.wxyz_abdis2]*, )?(1?-?[crtv][0-9][\\.wxyz_abdis2]*, )?((1?-)(c[0-9])([\\.wxyz]*)(_bx2|_bias|_x2|_d[zbwa]|)|(1?-?)(c[0-9])([\\.wxyz]*)(_bx2|_bias|_x2|_d[zbwa]))(?![_\\.wxyz])"),
" mov $4$5, $11$12$15$16 /* added line */\n$1 + $2$3 $4$5, $6$7$10$14$4$13$17 /* changed $11$12$15$16 to $4 */", std::regex_constants::format_first_only);
}
+
if (SourceSize == SourceCode.size())
- {
break;
- }
+
ArithmeticCount++;
}
@@ -1882,13 +1710,14 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreatePixelShader(const DWORD *pFunct
std::regex_search(SourceCode, std::regex("ps_1_[0-3]"))) // Verify PixelShader is using version 1.0 to 1.3
{
bool ConvertError = false;
- bool RegisterUsed[7] = { false };
- RegisterUsed[6] = true;
+ bool RegisterUsed[7] = { false, false, false, false, false, false, true };
+
struct MyStrings
{
std::string dest;
std::string source;
};
+
std::vector ReplaceReg;
std::string NewSourceCode = " ps_1_4 /* converted */\n";
@@ -2177,7 +2006,6 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::CreatePixelShader(const DWORD *pFunct
#ifndef D3D8TO9NOLOG
LOG << "> Failed to reassemble shader:" << std::endl << std::endl << static_cast(ErrorBuffer->GetBufferPointer()) << std::endl;
#endif
-
ErrorBuffer->Release();
}
else
@@ -2210,9 +2038,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::SetPixelShader(DWORD Handle)
HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetPixelShader(DWORD *pHandle)
{
if (pHandle == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*pHandle = CurrentPixelShaderHandle;
@@ -2221,14 +2047,10 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetPixelShader(DWORD *pHandle)
HRESULT STDMETHODCALLTYPE Direct3DDevice8::DeletePixelShader(DWORD Handle)
{
if (Handle == 0)
- {
return D3DERR_INVALIDCALL;
- }
if (CurrentPixelShaderHandle == Handle)
- {
SetPixelShader(0);
- }
reinterpret_cast(Handle)->Release();
@@ -2249,9 +2071,7 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::GetPixelShaderFunction(DWORD Handle,
#endif
if (Handle == 0)
- {
return D3DERR_INVALIDCALL;
- }
IDirect3DPixelShader9 *const PixelShaderInterface = reinterpret_cast(Handle);
@@ -2277,12 +2097,11 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice8::DeletePatch(UINT Handle)
void Direct3DDevice8::ApplyClipPlanes()
{
DWORD index = 0;
- for (const auto clipPlane : StoredClipPlanes)
+ for (const auto plane : StoredClipPlanes)
{
if ((ClipPlaneRenderState & (1 << index)) != 0)
- {
- ProxyInterface->SetClipPlane(index, clipPlane);
- }
+ ProxyInterface->SetClipPlane(index, plane);
+
index++;
}
}
\ No newline at end of file
diff --git a/source/d3d8to9_index_buffer.cpp b/source/d3d8to9_index_buffer.cpp
index 5960254..dd0a1da 100644
--- a/source/d3d8to9_index_buffer.cpp
+++ b/source/d3d8to9_index_buffer.cpp
@@ -5,7 +5,6 @@
#include "d3d8to9.hpp"
-// IDirect3DIndexBuffer8
Direct3DIndexBuffer8::Direct3DIndexBuffer8(Direct3DDevice8 *Device, IDirect3DIndexBuffer9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
@@ -18,27 +17,21 @@ Direct3DIndexBuffer8::~Direct3DIndexBuffer8()
HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
- {
return E_POINTER;
- }
if (riid == __uuidof(this) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(Direct3DResource8))
{
AddRef();
-
*ppvObj = this;
return S_OK;
}
- HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
-
+ const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
- {
- genericQueryInterface(riid, ppvObj, Device);
- }
+ GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
@@ -54,12 +47,9 @@ ULONG STDMETHODCALLTYPE Direct3DIndexBuffer8::Release()
HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::GetDevice(Direct3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
Device->AddRef();
-
*ppDevice = Device;
return D3D_OK;
@@ -100,7 +90,8 @@ HRESULT STDMETHODCALLTYPE Direct3DIndexBuffer8::Lock(UINT OffsetToLock, UINT Siz
D3DINDEXBUFFER_DESC desc;
ProxyInterface->GetDesc(&desc);
- if ((desc.Usage & D3DUSAGE_DYNAMIC) == 0 || (desc.Usage & D3DUSAGE_WRITEONLY) == 0)
+ if ((desc.Usage & D3DUSAGE_DYNAMIC) == 0 ||
+ (desc.Usage & D3DUSAGE_WRITEONLY) == 0)
{
Flags ^= D3DLOCK_DISCARD;
}
diff --git a/source/d3d8to9_surface.cpp b/source/d3d8to9_surface.cpp
index a613ff3..9313f83 100644
--- a/source/d3d8to9_surface.cpp
+++ b/source/d3d8to9_surface.cpp
@@ -5,7 +5,6 @@
#include "d3d8to9.hpp"
-// IDirect3DSurface8
Direct3DSurface8::Direct3DSurface8(Direct3DDevice8 *Device, IDirect3DSurface9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
@@ -18,26 +17,20 @@ Direct3DSurface8::~Direct3DSurface8()
HRESULT STDMETHODCALLTYPE Direct3DSurface8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
- {
return E_POINTER;
- }
if (riid == __uuidof(this) ||
riid == __uuidof(IUnknown))
{
AddRef();
-
*ppvObj = this;
return S_OK;
}
- HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
-
+ const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
- {
- genericQueryInterface(riid, ppvObj, Device);
- }
+ GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
@@ -53,9 +46,7 @@ ULONG STDMETHODCALLTYPE Direct3DSurface8::Release()
HRESULT STDMETHODCALLTYPE Direct3DSurface8::GetDevice(Direct3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
Device->AddRef();
@@ -77,30 +68,22 @@ HRESULT STDMETHODCALLTYPE Direct3DSurface8::FreePrivateData(REFGUID refguid)
}
HRESULT STDMETHODCALLTYPE Direct3DSurface8::GetContainer(REFIID riid, void **ppContainer)
{
- HRESULT hr = ProxyInterface->GetContainer(ConvertREFIID(riid), ppContainer);
-
+ const HRESULT hr = ProxyInterface->GetContainer(ConvertREFIID(riid), ppContainer);
if (SUCCEEDED(hr))
- {
- genericQueryInterface(riid, ppContainer, Device);
- }
+ GenericQueryInterface(riid, ppContainer, Device);
return hr;
}
HRESULT STDMETHODCALLTYPE Direct3DSurface8::GetDesc(D3DSURFACE_DESC8 *pDesc)
{
if (pDesc == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
D3DSURFACE_DESC SurfaceDesc;
const HRESULT hr = ProxyInterface->GetDesc(&SurfaceDesc);
-
if (FAILED(hr))
- {
return hr;
- }
ConvertSurfaceDesc(SurfaceDesc, *pDesc);
diff --git a/source/d3d8to9_swap_chain.cpp b/source/d3d8to9_swap_chain.cpp
index 339ee05..e2085b3 100644
--- a/source/d3d8to9_swap_chain.cpp
+++ b/source/d3d8to9_swap_chain.cpp
@@ -5,7 +5,6 @@
#include "d3d8to9.hpp"
-// IDirect3DSwapChain8
Direct3DSwapChain8::Direct3DSwapChain8(Direct3DDevice8 *Device, IDirect3DSwapChain9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
@@ -18,26 +17,20 @@ Direct3DSwapChain8::~Direct3DSwapChain8()
HRESULT STDMETHODCALLTYPE Direct3DSwapChain8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
- {
return E_POINTER;
- }
if (riid == __uuidof(this) ||
riid == __uuidof(IUnknown))
{
AddRef();
-
*ppvObj = this;
return S_OK;
}
- HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
-
+ const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
- {
- genericQueryInterface(riid, ppvObj, Device);
- }
+ GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
@@ -59,20 +52,15 @@ HRESULT STDMETHODCALLTYPE Direct3DSwapChain8::Present(const RECT *pSourceRect, c
HRESULT STDMETHODCALLTYPE Direct3DSwapChain8::GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, Direct3DSurface8 **ppBackBuffer)
{
if (ppBackBuffer == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppBackBuffer = nullptr;
IDirect3DSurface9 *SurfaceInterface = nullptr;
const HRESULT hr = ProxyInterface->GetBackBuffer(iBackBuffer, Type, &SurfaceInterface);
-
if (FAILED(hr))
- {
return hr;
- }
*ppBackBuffer = Device->ProxyAddressLookupTable->FindAddress(SurfaceInterface);
diff --git a/source/d3d8to9_texture.cpp b/source/d3d8to9_texture.cpp
index 890a26e..97f00c4 100644
--- a/source/d3d8to9_texture.cpp
+++ b/source/d3d8to9_texture.cpp
@@ -5,7 +5,6 @@
#include "d3d8to9.hpp"
-// IDirect3DTexture8
Direct3DTexture8::Direct3DTexture8(Direct3DDevice8 *Device, IDirect3DTexture9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
@@ -18,9 +17,7 @@ Direct3DTexture8::~Direct3DTexture8()
HRESULT STDMETHODCALLTYPE Direct3DTexture8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
- {
return E_POINTER;
- }
if (riid == __uuidof(this) ||
riid == __uuidof(IUnknown) ||
@@ -28,18 +25,14 @@ HRESULT STDMETHODCALLTYPE Direct3DTexture8::QueryInterface(REFIID riid, void **p
riid == __uuidof(Direct3DBaseTexture8))
{
AddRef();
-
*ppvObj = this;
return S_OK;
}
- HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
-
+ const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
- {
- genericQueryInterface(riid, ppvObj, Device);
- }
+ GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
@@ -55,12 +48,9 @@ ULONG STDMETHODCALLTYPE Direct3DTexture8::Release()
HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetDevice(Direct3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
Device->AddRef();
-
*ppDevice = Device;
return D3D_OK;
@@ -110,18 +100,13 @@ DWORD STDMETHODCALLTYPE Direct3DTexture8::GetLevelCount()
HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetLevelDesc(UINT Level, D3DSURFACE_DESC8 *pDesc)
{
if (pDesc == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
D3DSURFACE_DESC SurfaceDesc;
const HRESULT hr = ProxyInterface->GetLevelDesc(Level, &SurfaceDesc);
-
if (FAILED(hr))
- {
return hr;
- }
ConvertSurfaceDesc(SurfaceDesc, *pDesc);
@@ -130,20 +115,15 @@ HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetLevelDesc(UINT Level, D3DSURFACE_
HRESULT STDMETHODCALLTYPE Direct3DTexture8::GetSurfaceLevel(UINT Level, Direct3DSurface8 **ppSurfaceLevel)
{
if (ppSurfaceLevel == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppSurfaceLevel = nullptr;
IDirect3DSurface9 *SurfaceInterface = nullptr;
const HRESULT hr = ProxyInterface->GetSurfaceLevel(Level, &SurfaceInterface);
-
if (FAILED(hr))
- {
return hr;
- }
*ppSurfaceLevel = Device->ProxyAddressLookupTable->FindAddress(SurfaceInterface);
@@ -162,7 +142,6 @@ HRESULT STDMETHODCALLTYPE Direct3DTexture8::AddDirtyRect(const RECT *pDirtyRect)
return ProxyInterface->AddDirtyRect(pDirtyRect);
}
-// IDirect3DCubeTexture8
Direct3DCubeTexture8::Direct3DCubeTexture8(Direct3DDevice8 *device, IDirect3DCubeTexture9 *ProxyInterface) :
ProxyInterface(ProxyInterface),
Device(device)
@@ -176,9 +155,7 @@ Direct3DCubeTexture8::~Direct3DCubeTexture8()
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
- {
return E_POINTER;
- }
if (riid == __uuidof(this) ||
riid == __uuidof(IUnknown) ||
@@ -186,18 +163,14 @@ HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::QueryInterface(REFIID riid, void
riid == __uuidof(Direct3DBaseTexture8))
{
AddRef();
-
*ppvObj = this;
return S_OK;
}
- HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
-
+ const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
- {
- genericQueryInterface(riid, ppvObj, Device);
- }
+ GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
@@ -213,12 +186,9 @@ ULONG STDMETHODCALLTYPE Direct3DCubeTexture8::Release()
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetDevice(Direct3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
Device->AddRef();
-
*ppDevice = Device;
return D3D_OK;
@@ -268,18 +238,13 @@ DWORD STDMETHODCALLTYPE Direct3DCubeTexture8::GetLevelCount()
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetLevelDesc(UINT Level, D3DSURFACE_DESC8 *pDesc)
{
if (pDesc == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
D3DSURFACE_DESC SurfaceDesc;
const HRESULT hr = ProxyInterface->GetLevelDesc(Level, &SurfaceDesc);
-
if (FAILED(hr))
- {
return hr;
- }
ConvertSurfaceDesc(SurfaceDesc, *pDesc);
@@ -288,20 +253,15 @@ HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetLevelDesc(UINT Level, D3DSURF
HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, Direct3DSurface8 **ppCubeMapSurface)
{
if (ppCubeMapSurface == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppCubeMapSurface = nullptr;
IDirect3DSurface9 *SurfaceInterface = nullptr;
const HRESULT hr = ProxyInterface->GetCubeMapSurface(FaceType, Level, &SurfaceInterface);
-
if (FAILED(hr))
- {
return hr;
- }
*ppCubeMapSurface = Device->ProxyAddressLookupTable->FindAddress(SurfaceInterface);
@@ -320,7 +280,6 @@ HRESULT STDMETHODCALLTYPE Direct3DCubeTexture8::AddDirtyRect(D3DCUBEMAP_FACES Fa
return ProxyInterface->AddDirtyRect(FaceType, pDirtyRect);
}
-// IDirect3DVolumeTexture8
Direct3DVolumeTexture8::Direct3DVolumeTexture8(Direct3DDevice8 *device, IDirect3DVolumeTexture9 *ProxyInterface) :
ProxyInterface(ProxyInterface),
Device(device)
@@ -334,9 +293,7 @@ Direct3DVolumeTexture8::~Direct3DVolumeTexture8()
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
- {
return E_POINTER;
- }
if (riid == __uuidof(this) ||
riid == __uuidof(IUnknown) ||
@@ -344,18 +301,14 @@ HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::QueryInterface(REFIID riid, vo
riid == __uuidof(Direct3DBaseTexture8))
{
AddRef();
-
*ppvObj = this;
return S_OK;
}
- HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
-
+ const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
- {
- genericQueryInterface(riid, ppvObj, Device);
- }
+ GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
@@ -371,12 +324,9 @@ ULONG STDMETHODCALLTYPE Direct3DVolumeTexture8::Release()
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetDevice(Direct3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
Device->AddRef();
-
*ppDevice = Device;
return D3D_OK;
@@ -426,18 +376,13 @@ DWORD STDMETHODCALLTYPE Direct3DVolumeTexture8::GetLevelCount()
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetLevelDesc(UINT Level, D3DVOLUME_DESC8 *pDesc)
{
if (pDesc == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
D3DVOLUME_DESC VolumeDesc;
const HRESULT hr = ProxyInterface->GetLevelDesc(Level, &VolumeDesc);
-
if (FAILED(hr))
- {
return hr;
- }
ConvertVolumeDesc(VolumeDesc, *pDesc);
@@ -446,20 +391,15 @@ HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetLevelDesc(UINT Level, D3DVO
HRESULT STDMETHODCALLTYPE Direct3DVolumeTexture8::GetVolumeLevel(UINT Level, Direct3DVolume8 **ppVolumeLevel)
{
if (ppVolumeLevel == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
*ppVolumeLevel = nullptr;
IDirect3DVolume9 *VolumeInterface = nullptr;
const HRESULT hr = ProxyInterface->GetVolumeLevel(Level, &VolumeInterface);
-
if (FAILED(hr))
- {
return hr;
- }
*ppVolumeLevel = Device->ProxyAddressLookupTable->FindAddress(VolumeInterface);
diff --git a/source/d3d8to9_vertex_buffer.cpp b/source/d3d8to9_vertex_buffer.cpp
index c630612..ed70754 100644
--- a/source/d3d8to9_vertex_buffer.cpp
+++ b/source/d3d8to9_vertex_buffer.cpp
@@ -5,7 +5,6 @@
#include "d3d8to9.hpp"
-// IDirect3DVertexBuffer8
Direct3DVertexBuffer8::Direct3DVertexBuffer8(Direct3DDevice8 *Device, IDirect3DVertexBuffer9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
@@ -18,27 +17,21 @@ Direct3DVertexBuffer8::~Direct3DVertexBuffer8()
HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
- {
return E_POINTER;
- }
if (riid == __uuidof(this) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(Direct3DResource8))
{
AddRef();
-
*ppvObj = this;
return S_OK;
}
- HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
-
+ const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
- {
- genericQueryInterface(riid, ppvObj, Device);
- }
+ GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
@@ -54,12 +47,9 @@ ULONG STDMETHODCALLTYPE Direct3DVertexBuffer8::Release()
HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::GetDevice(Direct3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
Device->AddRef();
-
*ppDevice = Device;
return D3D_OK;
@@ -100,7 +90,8 @@ HRESULT STDMETHODCALLTYPE Direct3DVertexBuffer8::Lock(UINT OffsetToLock, UINT Si
D3DVERTEXBUFFER_DESC desc;
ProxyInterface->GetDesc(&desc);
- if ((desc.Usage & D3DUSAGE_DYNAMIC) == 0 || (desc.Usage & D3DUSAGE_WRITEONLY) == 0)
+ if ((desc.Usage & D3DUSAGE_DYNAMIC) == 0 ||
+ (desc.Usage & D3DUSAGE_WRITEONLY) == 0)
{
Flags ^= D3DLOCK_DISCARD;
}
diff --git a/source/d3d8to9_volume.cpp b/source/d3d8to9_volume.cpp
index 38a48b3..70350da 100644
--- a/source/d3d8to9_volume.cpp
+++ b/source/d3d8to9_volume.cpp
@@ -5,7 +5,6 @@
#include "d3d8to9.hpp"
-// IDirect3DVolume8
Direct3DVolume8::Direct3DVolume8(Direct3DDevice8 *Device, IDirect3DVolume9 *ProxyInterface) :
Device(Device), ProxyInterface(ProxyInterface)
{
@@ -18,26 +17,20 @@ Direct3DVolume8::~Direct3DVolume8()
HRESULT STDMETHODCALLTYPE Direct3DVolume8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
- {
return E_POINTER;
- }
if (riid == __uuidof(this) ||
riid == __uuidof(IUnknown))
{
AddRef();
-
*ppvObj = this;
return S_OK;
}
- HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
-
+ const HRESULT hr = ProxyInterface->QueryInterface(ConvertREFIID(riid), ppvObj);
if (SUCCEEDED(hr))
- {
- genericQueryInterface(riid, ppvObj, Device);
- }
+ GenericQueryInterface(riid, ppvObj, Device);
return hr;
}
@@ -53,12 +46,9 @@ ULONG STDMETHODCALLTYPE Direct3DVolume8::Release()
HRESULT STDMETHODCALLTYPE Direct3DVolume8::GetDevice(Direct3DDevice8 **ppDevice)
{
if (ppDevice == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
Device->AddRef();
-
*ppDevice = Device;
return D3D_OK;
@@ -77,30 +67,22 @@ HRESULT STDMETHODCALLTYPE Direct3DVolume8::FreePrivateData(REFGUID refguid)
}
HRESULT STDMETHODCALLTYPE Direct3DVolume8::GetContainer(REFIID riid, void **ppContainer)
{
- HRESULT hr = ProxyInterface->GetContainer(ConvertREFIID(riid), ppContainer);
-
+ const HRESULT hr = ProxyInterface->GetContainer(ConvertREFIID(riid), ppContainer);
if (SUCCEEDED(hr))
- {
- genericQueryInterface(riid, ppContainer, Device);
- }
+ GenericQueryInterface(riid, ppContainer, Device);
return hr;
}
HRESULT STDMETHODCALLTYPE Direct3DVolume8::GetDesc(D3DVOLUME_DESC8 *pDesc)
{
if (pDesc == nullptr)
- {
return D3DERR_INVALIDCALL;
- }
D3DVOLUME_DESC VolumeDesc;
const HRESULT hr = ProxyInterface->GetDesc(&VolumeDesc);
-
if (FAILED(hr))
- {
return hr;
- }
ConvertVolumeDesc(VolumeDesc, *pDesc);
diff --git a/source/interface_query.cpp b/source/interface_query.cpp
index 341d1e8..02100ee 100644
--- a/source/interface_query.cpp
+++ b/source/interface_query.cpp
@@ -4,30 +4,19 @@
*/
#define INITGUID
-
#include "d3d8to9.hpp"
-REFIID ConvertREFIID(REFIID riid)
+AddressLookupTable::~AddressLookupTable()
{
- return (riid == __uuidof(Direct3D8)) ? IID_IDirect3D9 :
- (riid == __uuidof(Direct3DDevice8)) ? IID_IDirect3DDevice9 :
- (riid == __uuidof(Direct3DTexture8)) ? IID_IDirect3DTexture9 :
- (riid == __uuidof(Direct3DCubeTexture8)) ? IID_IDirect3DCubeTexture9 :
- (riid == __uuidof(Direct3DVolumeTexture8)) ? IID_IDirect3DVolumeTexture9 :
- (riid == __uuidof(Direct3DVertexBuffer8)) ? IID_IDirect3DVertexBuffer9 :
- (riid == __uuidof(Direct3DIndexBuffer8)) ? IID_IDirect3DIndexBuffer9 :
- (riid == __uuidof(Direct3DSurface8)) ? IID_IDirect3DSurface9 :
- (riid == __uuidof(Direct3DVolume8)) ? IID_IDirect3DVolume9 :
- (riid == __uuidof(Direct3DSwapChain8)) ? IID_IDirect3DSwapChain9 :
- riid;
+ for (const auto &cache : AddressCache)
+ for (const auto &entry : cache)
+ entry.second->DeleteMe();
}
-void genericQueryInterface(REFIID riid, LPVOID *ppvObj, Direct3DDevice8* pDevice)
+void GenericQueryInterface(REFIID riid, LPVOID *ppvObj, Direct3DDevice8 *pDevice)
{
- if (!ppvObj || !*ppvObj || !pDevice)
- {
+ if (ppvObj == nullptr || *ppvObj == nullptr || pDevice == nullptr)
return;
- }
if (riid == __uuidof(Direct3D8))
{
@@ -46,19 +35,44 @@ void genericQueryInterface(REFIID riid, LPVOID *ppvObj, Direct3DDevice8* pDevice
return;
}
-#define QUERYINTERFACE(x) \
+#define QUERY_INTERFACE(x) \
if (riid == __uuidof(x)) \
- { \
- *ppvObj = pDevice->ProxyAddressLookupTable->FindAddress(*ppvObj); \
- return; \
- }
+ { \
+ *ppvObj = pDevice->ProxyAddressLookupTable->FindAddress(*ppvObj); \
+ return; \
+ }
- QUERYINTERFACE(Direct3DTexture8);
- QUERYINTERFACE(Direct3DCubeTexture8);
- QUERYINTERFACE(Direct3DVolumeTexture8);
- QUERYINTERFACE(Direct3DVertexBuffer8);
- QUERYINTERFACE(Direct3DIndexBuffer8);
- QUERYINTERFACE(Direct3DSurface8);
- QUERYINTERFACE(Direct3DVolume8);
- QUERYINTERFACE(Direct3DSwapChain8);
+ QUERY_INTERFACE(Direct3DTexture8);
+ QUERY_INTERFACE(Direct3DCubeTexture8);
+ QUERY_INTERFACE(Direct3DVolumeTexture8);
+ QUERY_INTERFACE(Direct3DVertexBuffer8);
+ QUERY_INTERFACE(Direct3DIndexBuffer8);
+ QUERY_INTERFACE(Direct3DSurface8);
+ QUERY_INTERFACE(Direct3DVolume8);
+ QUERY_INTERFACE(Direct3DSwapChain8);
+}
+
+REFIID ConvertREFIID(REFIID riid)
+{
+ if (riid == __uuidof(Direct3D8))
+ return IID_IDirect3D9;
+ if (riid == __uuidof(Direct3DDevice8))
+ return IID_IDirect3DDevice9;
+ if (riid == __uuidof(Direct3DTexture8))
+ return IID_IDirect3DTexture9;
+ if (riid == __uuidof(Direct3DCubeTexture8))
+ return IID_IDirect3DCubeTexture9;
+ if (riid == __uuidof(Direct3DVolumeTexture8))
+ return IID_IDirect3DVolumeTexture9;
+ if (riid == __uuidof(Direct3DVertexBuffer8))
+ return IID_IDirect3DVertexBuffer9;
+ if (riid == __uuidof(Direct3DIndexBuffer8))
+ return IID_IDirect3DIndexBuffer9;
+ if (riid == __uuidof(Direct3DSurface8))
+ return IID_IDirect3DSurface9;
+ if (riid == __uuidof(Direct3DVolume8))
+ return IID_IDirect3DVolume9;
+ if (riid == __uuidof(Direct3DSwapChain8))
+ return IID_IDirect3DSwapChain9;
+ return riid;
}
diff --git a/source/lookup_table.hpp b/source/interface_query.hpp
similarity index 73%
rename from source/lookup_table.hpp
rename to source/interface_query.hpp
index fe2deaa..904bad7 100644
--- a/source/lookup_table.hpp
+++ b/source/interface_query.hpp
@@ -5,8 +5,8 @@
#pragma once
-#include
#include
+#include
class AddressLookupTable
{
@@ -39,23 +39,20 @@ class AddressLookupTable
public:
- explicit AddressLookupTable(Direct3DDevice8 *Device);
+ explicit AddressLookupTable(Direct3DDevice8 *Device) : Device(Device) {}
~AddressLookupTable();
template
T *FindAddress(void *pAddress9)
{
if (pAddress9 == nullptr)
- {
return nullptr;
- }
- auto it = AddressCache[AddressCacheIndex::CacheIndex].find(pAddress9);
+ auto &cache = AddressCache[AddressCacheIndex::CacheIndex];
- if (it != std::end(AddressCache[AddressCacheIndex::CacheIndex]))
- {
+ const auto it = cache.find(pAddress9);
+ if (it != cache.end())
return static_cast(it->second);
- }
return new T(Device, static_cast::Type9 *>(pAddress9));
}
@@ -64,9 +61,7 @@ class AddressLookupTable
void SaveAddress(T *pAddress8, void *pAddress9)
{
if (pAddress8 == nullptr || pAddress9 == nullptr)
- {
return;
- }
AddressCache[AddressCacheIndex::CacheIndex][pAddress9] = pAddress8;
}
@@ -75,33 +70,32 @@ class AddressLookupTable
void DeleteAddress(T *pAddress8)
{
if (pAddress8 == nullptr)
- {
return;
- }
-
- constexpr UINT CacheIndex = AddressCacheIndex::CacheIndex;
- auto it = std::find_if(AddressCache[CacheIndex].begin(), AddressCache[CacheIndex].end(),
- [pAddress8](std::pair Map) -> bool { return Map.second == pAddress8; });
+ auto &cache = AddressCache[AddressCacheIndex::CacheIndex];
- if (it != std::end(AddressCache[CacheIndex]))
- {
- it = AddressCache[CacheIndex].erase(it);
- }
+ const auto it = std::find_if(cache.begin(), cache.end(),
+ [pAddress8](std::pair Map) -> bool { return Map.second == pAddress8; });
+ if (it != cache.end())
+ cache.erase(it);
}
private:
Direct3DDevice8 *const Device;
- std::unordered_map AddressCache[8];
+ std::unordered_map AddressCache[8];
};
class AddressLookupTableObject
{
public:
- virtual ~AddressLookupTableObject() { }
+ virtual ~AddressLookupTableObject() {}
void DeleteMe()
{
delete this;
}
};
+
+void GenericQueryInterface(REFIID riid, LPVOID *ppvObj, class Direct3DDevice8 *pDevice);
+
+REFIID ConvertREFIID(REFIID riid);
diff --git a/source/lookup_table.cpp b/source/lookup_table.cpp
deleted file mode 100644
index 4bbffeb..0000000
--- a/source/lookup_table.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Copyright (C) 2015 Patrick Mours. All rights reserved.
- * License: https://github.com/crosire/d3d8to9#license
- */
-
-#include "d3d8to9.hpp"
-#include
-
-AddressLookupTable::AddressLookupTable(Direct3DDevice8 *Device) :
- Device(Device)
-{
- // Do nothing
-}
-AddressLookupTable::~AddressLookupTable()
-{
- for (const auto& cache : AddressCache)
- {
- for (const auto& entry : cache)
- {
- entry.second->DeleteMe();
- }
- }
-}