Skip to content
Permalink
Browse files

Overlay: Introduce hook for ResetEx. Hook PresentEx.

* For D3D9Ex
** Hook PresentEx
** Hook ResetEx
  • Loading branch information...
Kissaki committed May 15, 2013
1 parent 123486b commit 1182fc26cb7c0c9452bd0b677ac0a34cd6d843e6
Showing with 35 additions and 0 deletions.
  1. +35 −0 overlay/d3d9.cpp
@@ -308,6 +308,7 @@ void DevState::createCleanState() {
static HardHook hhCreateDevice;
static HardHook hhCreateDeviceEx;
static HardHook hhReset;
static HardHook hhResetEx;
static HardHook hhAddRef;
static HardHook hhRelease;
static HardHook hhPresent;
@@ -434,6 +435,34 @@ static HRESULT __stdcall myReset(IDirect3DDevice9 * idd, D3DPRESENT_PARAMETERS *
return hr;
}

typedef HRESULT(__stdcall *ResetExType)(IDirect3DDevice9Ex *, D3DPRESENT_PARAMETERS *, D3DDISPLAYMODEEX *);
static HRESULT __stdcall myResetEx(IDirect3DDevice9Ex * idd, D3DPRESENT_PARAMETERS *param, D3DDISPLAYMODEEX * param2) {
ods("D3D9: Chaining ResetEx");

DevState *ds = devMap[idd];
if (ds) {
DWORD dwOldThread = ds->dwMyThread;
if (dwOldThread)
ods("D3D9: myResetEx from other thread");
ds->dwMyThread = GetCurrentThreadId();

ds->releaseAll();
ds->dwMyThread = dwOldThread;
}

//TODO: Move logic to HardHook.
// Call base without active hook in case of no trampoline.
ResetExType oResetEx = (ResetExType) hhResetEx.call;
hhResetEx.restore();
HRESULT hr = oResetEx(idd, param, param2);
hhResetEx.inject();

if (ds)
ds->createCleanState();

return hr;
}

typedef ULONG(__stdcall *AddRefType)(IDirect3DDevice9 *);
static ULONG __stdcall myAddRef(IDirect3DDevice9 *idd) {
Mutex m;
@@ -698,6 +727,9 @@ static HRESULT __stdcall myCreateDeviceEx(IDirect3D9Ex * id3d, UINT Adapter, D3D
const unsigned int offsetRelease = 2;
const unsigned int offsetReset = 16;
const unsigned int offsetPresent = 17;
// On IDirect3DDevice9Ex
const unsigned int offsetPresentEx = 121;
const unsigned int offsetResetEx = 132;
if (bIsWin8) {
hhAddRef.setupInterface(idd, offsetAddref, reinterpret_cast<voidFunc>(myWin8AddRef));
hhRelease.setupInterface(idd, offsetRelease, reinterpret_cast<voidFunc>(myWin8Release));
@@ -706,7 +738,9 @@ static HRESULT __stdcall myCreateDeviceEx(IDirect3D9Ex * id3d, UINT Adapter, D3D
hhRelease.setupInterface(idd, offsetRelease, reinterpret_cast<voidFunc>(myRelease));
}
hhReset.setupInterface(idd, offsetReset, reinterpret_cast<voidFunc>(myReset));
hhResetEx.setupInterface(idd, offsetResetEx, reinterpret_cast<voidFunc>(myResetEx));
hhPresent.setupInterface(idd, offsetPresent, reinterpret_cast<voidFunc>(myPresent));
hhPresentEx.setupInterface(idd, offsetPresentEx, reinterpret_cast<voidFunc>(myPresentEx));

IDirect3DSwapChain9 *pSwap = NULL;
idd->GetSwapChain(0, &pSwap);
@@ -822,6 +856,7 @@ void freeD3D9Hook(HMODULE hModule) {
hhCreateDevice.reset();
hhCreateDeviceEx.reset();
hhReset.reset();
hhResetEx.reset();
hhAddRef.reset();
hhRelease.reset();
hhPresent.reset();

0 comments on commit 1182fc2

Please sign in to comment.
You can’t perform that action at this time.