Skip to content

Add error handling to shims. #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions d3d11/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ typedef HRESULT(WINAPI* D3D11CreateDeviceAndSwapChainFunc)(IDXGIAdapter* pAdapte
HMODULE target_lib = 0;
const wchar_t* target_lib_name = L"addonLoader.dll";

/* proto */
HMODULE GetD3D11Module();

void* getTargetProc(const char* procName)
{
if (!target_lib)
{
target_lib = LoadLibrary(target_lib_name);
}

if (!target_lib)
{
target_lib = GetD3D11Module();
}

return GetProcAddress(target_lib, procName);
}

Expand All @@ -52,6 +60,9 @@ extern "C" HRESULT WINAPI D3D11CreateDevice(IDXGIAdapter * pAdapter, D3D_DRIVER_
extern "C" HRESULT WINAPI D3D11CreateDeviceAndSwapChain(IDXGIAdapter * pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, const D3D_FEATURE_LEVEL * pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, const DXGI_SWAP_CHAIN_DESC * pSwapChainDesc, IDXGISwapChain * *ppSwapChain, ID3D11Device * *ppDevice, D3D_FEATURE_LEVEL * pFeatureLevel, ID3D11DeviceContext * *ppImmediateContext)
{
D3D11CreateDeviceAndSwapChainFunc fun = (D3D11CreateDeviceAndSwapChainFunc)getTargetProc("D3D11CreateDeviceAndSwapChain");

if (!fun)
return E_HANDLE;

return fun(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext);
}
Expand Down Expand Up @@ -98,6 +109,10 @@ extern "C" HRESULT WINAPI D3D11CoreCreateDevice(
{
if(ShouldTryLoading)
LoadAllFunctions();

if (!RealD3D11CoreCreateDevice)
return E_HANDLE;

return RealD3D11CoreCreateDevice(pFactory, pAdapter, Flags, pFeatureLevels, FeatureLevels, ppDevice);
}

Expand All @@ -110,20 +125,32 @@ extern "C" HRESULT WINAPI D3D11CoreCreateLayeredDevice(
{
if(ShouldTryLoading)
LoadAllFunctions();

if (!RealD3D11CoreCreateLayeredDevice)
return E_HANDLE;

return RealD3D11CoreCreateLayeredDevice(unknown0, unknown1, unknown2, riid, ppvObj);
}

extern "C" SIZE_T WINAPI D3D11CoreGetLayeredDeviceSize(const void* unknown0, DWORD unknown1)
{
if(ShouldTryLoading)
LoadAllFunctions();

if (!RealD3D11CoreGetLayeredDeviceSize)
return E_HANDLE;

return RealD3D11CoreGetLayeredDeviceSize(unknown0, unknown1);
}

extern "C" HRESULT WINAPI D3D11CoreRegisterLayers(const void* unknown0, DWORD unknown1)
{
if(ShouldTryLoading)
LoadAllFunctions();

if (!RealD3D11CoreRegisterLayers)
return E_HANDLE;

return RealD3D11CoreRegisterLayers(unknown0, unknown1);
}

Expand Down
32 changes: 32 additions & 0 deletions dxgi/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,61 @@ typedef HRESULT(WINAPI* DXGIDebugInterfaceGet1)(UINT Flags, REFIID riid, void**
HMODULE target_lib = 0;
const wchar_t* target_lib_name = L"addonLoader.dll";

/* proto */
HMODULE GetDXGIModule();

void* getTargetProc(const char* procName)
{
if (!target_lib)
{
target_lib = LoadLibrary(target_lib_name);
}

if (!target_lib)
{
target_lib = GetDXGIModule();
}

return GetProcAddress(target_lib, procName);
}

HRESULT WINAPI CreateDXGIFactory(REFIID riid, void** ppFactory)
{
DXGIFactoryCreate0 fun = (DXGIFactoryCreate0)getTargetProc("CreateDXGIFactory");

if (!fun)
return E_HANDLE;

return fun(riid, ppFactory);
}

HRESULT WINAPI CreateDXGIFactory1(REFIID riid, void** ppFactory)
{
DXGIFactoryCreate1 fun = (DXGIFactoryCreate1)getTargetProc("CreateDXGIFactory1");

if (!fun)
return E_HANDLE;

return fun(riid, ppFactory);
}

HRESULT WINAPI CreateDXGIFactory2(UINT Flags, REFIID riid, void** ppFactory)
{
DXGIFactoryCreate2 fun = (DXGIFactoryCreate2)getTargetProc("CreateDXGIFactory2");

if (!fun)
return E_HANDLE;

return fun(Flags, riid, ppFactory);
}

HRESULT DXGIGetDebugInterface1(UINT Flags, REFIID riid, void** pDebug)
{
DXGIDebugInterfaceGet1 fun = (DXGIDebugInterfaceGet1)getTargetProc("DXGIGetDebugInterface1");

if (!fun)
return E_HANDLE;

return fun(Flags, riid, pDebug);
}

Expand Down Expand Up @@ -84,13 +108,21 @@ extern "C" BOOL WINAPI CompatValue(LPCSTR szName, UINT64 *pValue)
{
if(ShouldTryLoading)
LoadAllFunctions();

if (!RealCompatValue)
return E_HANDLE;

return RealCompatValue(szName, pValue);
}

extern "C" BOOL WINAPI CompatString(LPCSTR szName, ULONG *pSize, LPSTR lpData, bool Flag)
{
if(ShouldTryLoading)
LoadAllFunctions();

if (!RealCompatString)
return E_HANDLE;

return RealCompatString(szName, pSize, lpData, Flag);
}

Expand Down